2.0.0 • Published 2 years ago

express-mongoose-common-service v2.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

If you use Express.js and Mongoose, these common services may be helpful for you

USAGE:

const emcs = require("express-mongoose-common-service");
const testService = emcs.generate(dbTable, identifierName, returnMsg);

OR

import emcs from "express-mongoose-common-service";
const testService = emcs.generate(dbTable, identifierName, returnMsg);

In which,

  1. dbTable: is the mongoose table, ex. db.Test
  2. identifierName: the identifer field in your table, in my case that is 'id'
  3. returnMsg: you can leave this argument empty to use the default value as below
returnMsg = {
  createFailDuplicate: (identifierValue) =>
    `Id ${identifierValue} is already taken.`,
  updateFailValidate: "Record can not be found",
  updateFailDuplicate: (identifierValue) =>
    `Id ${identifierValue} is already taken.`,
};

or override it on your own will.

Methods return on calling the method generate:

  1. getAll
  2. getById
  3. create
  4. update
  5. delete
  6. getAllByUserId
  7. getByIdByUserId
  8. createByUserId
  9. updateByUserId
  10. deleteByUserId
  11. backup
  12. getAllWithPagination
  13. getAllWithPaginationByUserId

To use getAllWithPagination & getAllWithPaginationByUserId, install mongoose-paginate-v2 and add it to your schema before using these functions

Note: getAll, getById, getAllByUserId, getByIdByUserId can use populate by passing populate param as the final param

Note: you should add 'isDeleted' and 'userId' to your table,

With the delete function, we just marked it as isDeleted = true, we are not actually removed it.

2.0.0

2 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.10

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago