Created
December 4, 2020 15:04
-
-
Save izonder/0d003955b160e8fa49e81ef1445ae523 to your computer and use it in GitHub Desktop.
statuses transitions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {makeFlag, isBitsOn, isBitsOff, turnBitsOn, turnBitsOff} from '../helpers/bitwise'; | |
/** | |
* Statuses dictionary | |
* @type {number} | |
*/ | |
export const | |
F_FINALIZED = makeFlag(0), // finalized | |
F_QUEUED_FOR_FETCHING = makeFlag(1), // marked for queue to be fetched | |
F_READY_FOR_PROCESSING = makeFlag(2), // marked for processing | |
F_PROCESSED = makeFlag(3), // processed successfully | |
F_ERROR = makeFlag(4), // processed with error | |
STATUS_INIT = 0; | |
export default class NsInvoiceModel extends BaseModel { | |
// ... | |
/** | |
* Turn the invoice status as finalized | |
* @returns {OrderModel} | |
*/ | |
turnFinalized() { | |
return this.turnOn(F_FINALIZED).turnOff(F_QUEUED_FOR_FETCHING); | |
} | |
/** | |
* Turn the invoice status as ready for process | |
* @returns {OrderModel} | |
*/ | |
turnReadyForProcess() { | |
return this.turnOn(F_READY_FOR_PROCESS); | |
} | |
/** | |
* Turn the invoice status as processed | |
* @returns {OrderModel} | |
*/ | |
turnProcessed() { | |
return this.turnOff(F_READY_FOR_PROCESS).turnOff(F_ERROR).turnOn(F_PROCESSED); | |
} | |
/** | |
* Turn the invoice status as processed | |
* @returns {OrderModel} | |
*/ | |
turnError() { | |
return this.turnOff(F_READY_FOR_PROCESS).turnOff(F_ERROR).turnOn(F_PROCESSED); | |
} | |
/** | |
* Turn flags on abstract method | |
* @param {number} flag | |
* @returns {OrderModel} | |
*/ | |
turnOn(flag) { | |
this.status = turnBitsOn(this.status, flag); | |
return this; | |
} | |
/** | |
* Turn flags off abstract method | |
* @param {number} flag | |
* @returns {OrderModel} | |
*/ | |
turnOff(flag) { | |
this.status = turnBitsOff(this.status, flag); | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment