Skip to content

Latest commit

 

History

History
233 lines (207 loc) · 10.3 KB

README.md

File metadata and controls

233 lines (207 loc) · 10.3 KB

Utilisation

  • DO NOT USE NODE 8 nodejs/node#12675: (console.debug not displayed).
  • Code must be run with node appJS/server.js db=mongoose\' or node appJS/server.js db=mongonative'
    • Mongoose and the bare MongoDB Node.js Driver have different DB, it's more safe.
  • If the port 8080 is already in use, exit with error code 2.
  • If you have forgotten to start MongoDB service, or if there is a problem to be connected to the database, the application exit with error code 3.
  • You should not have two same idSSN. My code check that idSSN should be UNIQUE.

Quick start and development

  • Run:
    yarn tscwatch
  • Or
    make
  • Compile in watch mode, then on compilation success launch the linter, then launch the server (even if there are linter errors).

Patches

  • RXJS SHOULD BE PATCH.
    • patch ./node_modules/rxjs/scheduler/VirtualTimeScheduler.d.ts < VirtualTimeScheduler.d.ts.patch
    • See also ReactiveX/rxjs#3031
  • tsc-watch should be patch (TODO post an issue on the project) patch ./node_modules/tsc-watch/lib/tsc-watch.js < tsc-watch.js.patch
  • WARNING. SHOULD BE PATCHED EACH TIME YOU EXECUTE yarn add XXXXX

Compilation

Debugger

  • You could use https://nodejs.org/en/docs/inspector/
    • If you use one of this, comment require(console-*) in server.ts (and which corresponds to in ./package.json)
  • The addon Node.js V8 doesn't work with Chromium. It's a shit !
    • I've seen some intempestives and unexpected deconnection, so I come back to my terminal. But I think it could be very cool to see all variables values at a break point and « pause on exception ». No regret to see this, I could come back. But some « pros » code with console.* !
  • Use too Open-as-Popup to doesn't show the shit Google Chrome layout and logos !
  • TODO try to use Firefox debugger instead, but I've not found really cool documentation on it.. There is https://github.com/devtools-html/debugger.html/blob/master/docs/getting-setup.md#starting-node. I've tested but doesn't seems to work well.

Create a new Entity inherited from Person

  1. cp -R patient nurse
  2. sed -i -e 's/patient/nurse/g' *
  3. Change the model, and the json associated.
  4. From the model, change the file route
  5. Declare the route

TODO

  • Use an hot reload. Done.
  • Add an entity address.
  • regex for some req.body.*. See:
  • ~~ Implement an abstract dbMongo.service.ts ~~ Done.
  • Test if MongoDB is running https://stackoverflow.com/questions/39599063/check-if-mongodb-is-connected and adapt dbMongo.ts Done.
  • In France, the Sécurité sociale use not the Social security number as key (too complex). Like them, do not use SSN. In file ./shared/abstract.entity.ts, add "id: number". Only with Mongo it seems not be possible to have a field UNIQUE, except if this field is the identifier. Use Mongoose or JSON Schema to resolve that. mongodb automatically add an identifier with field '_id'. my code check that idssn is unique.
  • Secure abstract.service.ts against SQL injections.
  • See how to secure server against XSS injection.
  • In MongoDB 2.2 and MongoDB 3.0, save method is deprecated. Change method insertOrUpdateNested with method updateOne. Use behaviour of JHipster.
  • Update to Node.js MongoDB Driver 3.0
  • Publish console-debug in npm, or ask author of console.info to do this. Use instead https://nodejs.org/en/docs/inspector/
  • Maybe try to use a logger…. => Maybe we could use https://stackoverflow.com/questions/45395369/how-to-get-console-log-line-numbers-shown-in-nodejs.
  • tsc --watch won't compile server.ts, but compile good all other files. fixed by write in package.json "app/.ts" before and after « "app/**/.ts", ». doesn't work very well. Work until next Node.js reboot.
  • Why we must have "const mongoose = require('mongoose');" in ./utils/db-mongoose.init.ts?
  • TODO Maybe delete duplications in ./tslint.yaml (but actually could see chosen rules)
  • TODO: see under subtitle "Debugger" above.
  • In patient.schema.ts and patient.model.ts, change _birthday to type Date.
  • Maybe post an issue in https://github.com/parshap/check-node-version/. This plugin is totally buggy with es6 keyword import and my TypeScript configuration. I've used a safer and more correct solution in the file server.ts.
  • See section #Patches above.
  • Post a PR in project mongoose. In file *.d.ts Model.findById* havn't option rawResult in its option.
  • Not interesting to use type T[] instead of Array In file ../back/entities/abstract/abstract.route.ts when I use T[] I have an error with spread notation. On Github I've found that use Array can give the same error. TODO resolve it. See tslint.yaml

MongoDB

Mongoose

Routes

See

Routes patients

(with express.Router middleware, Router-level middleware, could have error-handling middleware) "mongonative" and "mongoose" havn't the same database.

  • « :driver » must be replaced either by mongoose or by mongonative.
    • mongoose use the mongoose Driver
    • mongonative use bare MongoDB Node.js Driver
  • GET /:driver/patients (get all patients)
  • PUT /:driver/patients (idempotent, so UPDATE and CREATE)
  • GET /:driver/patients/:id (get the patient with id :id)
  • DELETE /patients/:id (delete the patient with id :id)

Routes nurses

(with express.Router middleware, Router-level middleware, could have error-handling middleware)

  • GET /:driver/nurses (get all nurses)
  • PUT /:driver/nurses (idempotent, so UPDATE and CREATE)
  • GET /:driver/nurses/:id (get the nurse with id :id)
  • DELETE /:driver/nurses/:id (delete the nurse with id :id)

Others routes

(with express route (app.get, etc.): application-level middleware)

  • GET /
  • GET /test
  • GET /testParam
  • GET /testParam2
  • GET /* 404

Notes for developers

  • Be careful to circular dependencies with index.ts. Read: ./AnotherCircularDependenciesError/README.md and microsoft/TypeScript#21225 Automatically detected thanks a linter rule.
  • We must send the REST error thanks:
    console.error(JSON.stringify(err)); // better for me than toString()
    reject(err); // we have the same result as above
* Deprecated collection methods from mongodb
    * https://github.com/Automattic/mongoose/issues/6880
    * https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
    * See corresponding code at ./app/utils/db-mongoose.init.ts

* Note: for ./app/entities/abstract/abstract.mongoose.service.ts
    `Promise<mongoose.Document>` could become
    `Promise<IAbstract>` could become if IAbstract inherit mongoose.Document

* abstract.model.ts is used by Mongoose, and all properties should be in
    the constructor! Otherwise can't parse to JSON.

* Mongonative don't manage timestamps actually

* We could have `_id=null`, that's why we use boson to generate id.

* For abstract.mongonative.service.ts/insertOrUpdate()
    if (obj.id) and object not already created
    obj.createdAt will be null.
    Furthermore in this case we can't deduce created date
    from id.

* For update timestamp in Mongoose see https://github.com/Automattic/mongoose/issues/4768
    actually I manually set updateAt