node.js - Architecture for a recurring workorder system -


i'm hoping advice on designing workorder system has support recurring workorders. example, administrator needs able set workorder repeat in unit of time every 6-months.

i'm using nodejs server, nosql database (couchdb) storage , elasticsearch search engine. here's first attempt @ document structure support this:

base workorder {    _id: 1    ... unrelated fields    "recurinvalue" : 6,    "recurinunit" : "months"    "lastrecurredon": 1368914552527,    "numocurrences": 1,    "numtimestorepeat": null,    "stopon" : 1384920941195,    "createdat" 1364936177618 }  occurrence workorder {    _id: 2    ... unrelated fields    "recurfrom" : 1 }  occurrence workorder {    _id: 3    ... unrelated fields    "recurfrom" : 1 } 

my current crud plan is:

create

a cron job poll database hourly , of workorders have non-empty recurinvalue (base workorders). calculate actual date of recurrence adding time given recurinvalue , recurinunit lastrecurredon, if present, or createdat, if not. moment.js works great this. if actual date of recurrence <= now, system copy workorder, set recurfrom property base workorder's id, , update appropriate fields.

read

this 1 little tricky workorders have associated notes, activity log entries, , system log entries. these associated items live in own documents have workorderid property set parent workorder's id. locating individual workorder's associated documents trivial , done couchdb.

however, using notes example, customer wants see of notes past workorders along occurrence workorder's notes. i've got working using elasticsearch find of workorderids either share same recurfrom value (id of base workorder) or have _id matches workorder's recurfrom property (base workorder). system bulk fetches corresponding notes in createdat order (chronological) , passes them off view.

i haven't worked out how display though. user in theory add note previous workorder after latest note on 1 user viewing displaying notes in chronological order may confusing. might able around in view differentiating current workorder's notes other notes color or in separate sections, i'm not sure that.

update

one thing seems tricky here updating recurinvalue. if changes, think need change base workorder, not occurrence workorder, example, if user clears out recurinvalue workorder stop repeating.

delete

i'm still little fuzzy on this. if user wants delete occurrence workorder, can delete , associated documents , ask them if want stop workorder repeating. if yes, can clear out base workorder's recurinvalue.

if user deletes base workorder, repeating stop of occurrence workorders have recurfrom property points non-existent document. if leave recurfrom property is, able load occurrence workorer's associated documents , display them properly, doesn't feel right.

other options

i'm not tied implementation, it's i've come far. considered linked list implementation each occurrence workorder point previous workorder, seems having 'walk list' in long chain of workorders , load each workorder's associated documents individually result in excessive number of queries , not efficient.

any advice can give me appreciated!


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -