A progressive Node.js framework for building efficient and scalable server-side applications.
Test project utilizing Mongo Graph.
$ npm i -g yarn @nest/cli
$ yarn
Set your constant config in the src/configs/constants.ts
file. Please note the mongo URL string you enter here, should be the one you will enter must be the same as <YOUR_MONGODB_URL_STRING>
in running the seeder.
# development
$ yarn start
# watch mode
$ yarn start:dev
# production mode
$ yarn start:prod
# initialize the DB with necessary data
$ node dist/store-seeder-script.js <YOUR_MONGODB_URL_STRING>
# unit tests
$ yarn test
# e2e tests
$ yarn test:e2e
-
I added
status
field to soft-delete entities, so I don't remove them from DB. -
I aggregate user API with different type of
MANAGER
andEMPLOYEE
in one API as I think it makes sense to do so because they are different in onlytype
query filter. -
I could reference the child stores in
store
model but I preferred to saveparenetStore
as the project could grow, and it is not efficient to save let’s say for example50
entries aschildStore
for eachstore.
-
I used
bcryptjs
for hashingpassword
s for the sake of simplicity, but in production projects, we should usebcrypt
as it usesC
under the hood and is almost100
times faster thanbcryptjs
which usesJavaScript
for the same tasks. -
I used the
name
asusername
andpassword
of the users in theseeder script
for the sake of brevity. -
I used the DB properties as inputs and outputs for the sake of simplicity, but in the production project, I prefer
snake_case_keys
for request and response andcamelCase
for database schema. -
Right now the
refreshToken
field of the user model is useless, I would add another API to get the sameaccessToken
as its response withrefreshToken
as its request to provide a better DX for clients. -
The
Authorization
mechanism which uses only oneInterceptor
is so fragile and is completely route-dependent and I could useCASL
orcasbin
libraries in the production project, considering whether I had the time to implement it.
This project can be improved with the following developments:
- Replace
bcryptjs
withbcrypt
. - Refactor the project so inputs and outputs keys would not be the same as DB fields. For example, replace
_id
withid
and remove__v
field usingtoJSON
mongoose built-in virtual. - Add an API that accepts
refresh_token
as its request body and returns theOAuth2
standard response. - Overhaul the
Authorization
withCASL
orcasbin
libraries.
Thank You :)