@dracul/audit-backend 1.29.2 → 1.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,16 +5,22 @@ const {
5
5
  UserInputError
6
6
  } = require('apollo-server-errors');
7
7
  const findAudit = async function (id) {
8
- return new Promise((resolve, reject) => {
9
- Audit.findOne({
8
+ try {
9
+ const audit = await Audit.findOne({
10
10
  _id: id
11
- }).populate('user').exec((err, res) => err ? reject(err) : resolve(res));
12
- });
11
+ }).populate('user').exec();
12
+ return audit;
13
+ } catch (e) {
14
+ throw e;
15
+ }
13
16
  };
14
17
  const fetchAudit = async function () {
15
- return new Promise((resolve, reject) => {
16
- Audit.find({}).populate('user').exec((err, res) => err ? reject(err) : resolve(res));
17
- });
18
+ try {
19
+ const audit = await Audit.find({}).populate('user').exec();
20
+ return audit;
21
+ } catch (e) {
22
+ throw e;
23
+ }
18
24
  };
19
25
  const paginateAudit = function (pageNumber = 1, itemsPerPage = 5, search = null, filters = null, orderBy = null, orderDesc = false) {
20
26
  function qs(search, filters) {
@@ -93,26 +99,24 @@ const createAudit = async function (authUser, {
93
99
  resource,
94
100
  description
95
101
  }) {
96
- const doc = new Audit({
97
- user,
98
- action,
99
- resource,
100
- description
101
- });
102
- doc.id = doc._id;
103
- return new Promise((resolve, rejects) => {
104
- doc.save(error => {
105
- if (error) {
106
- if (error.name == "ValidationError") {
107
- return rejects(new UserInputError(error.message, {
108
- inputErrors: error.errors
109
- }));
110
- }
111
- return rejects(error);
112
- }
113
- doc.populate('user').execPopulate(() => resolve(doc));
102
+ try {
103
+ const doc = new Audit({
104
+ user,
105
+ action,
106
+ resource,
107
+ description
114
108
  });
115
- });
109
+ doc.id = doc._id;
110
+ await doc.populate('user');
111
+ return doc;
112
+ } catch (error) {
113
+ if (error.name == "ValidationError") {
114
+ throw new UserInputError(error.message, {
115
+ inputErrors: error.errors
116
+ });
117
+ }
118
+ throw error;
119
+ }
116
120
  };
117
121
  module.exports = {
118
122
  createAudit,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dracul/audit-backend",
3
- "version": "1.29.2",
3
+ "version": "1.30.0",
4
4
  "description": "Audit Backend",
5
5
  "author": "Cristian Incarnato <cristian.cdi@gmail.com>",
6
6
  "homepage": "https://github.com/draculjs/modular-framework#readme",
@@ -10,6 +10,10 @@
10
10
  "lib": "lib",
11
11
  "test": "__tests__"
12
12
  },
13
+ "scripts": {
14
+ "prepublish": "babel src -d lib --copy-files",
15
+ "test": "echo \"Error: run tests from root\" && exit 1"
16
+ },
13
17
  "files": [
14
18
  "lib"
15
19
  ],
@@ -17,19 +21,15 @@
17
21
  "type": "git",
18
22
  "url": "git+https://github.com/draculjs/modular-framework.git"
19
23
  },
20
- "scripts": {
21
- "prepublish": "babel src -d lib --copy-files",
22
- "test": "echo \"Error: run tests from root\" && exit 1"
23
- },
24
24
  "bugs": {
25
25
  "url": "https://github.com/draculjs/modular-framework/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@dracul/common-backend": "^1.29.2",
28
+ "@dracul/common-backend": "^1.30.0",
29
29
  "@dracul/logger-backend": "^1.29.2",
30
- "@dracul/notification-backend": "^1.29.2",
31
- "@dracul/settings-backend": "^1.29.2",
32
- "@dracul/user-backend": "^1.29.2"
30
+ "@dracul/notification-backend": "^1.30.0",
31
+ "@dracul/settings-backend": "^1.30.0",
32
+ "@dracul/user-backend": "^1.30.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@graphql-tools/load-files": "^7.0.0",
@@ -37,10 +37,10 @@
37
37
  "apollo-server-errors": "^3.3.1",
38
38
  "dayjs": "^1.11.11",
39
39
  "graphql": "^15.8.0 || ^16.0.0",
40
- "mongoose": "5.13.21",
40
+ "mongoose": "5.13.22",
41
41
  "mongoose-paginate-v2": "1.7.4",
42
42
  "mongoose-softdelete": "1.1.0",
43
43
  "mongoose-unique-validator": "^2.0.3"
44
44
  },
45
- "gitHead": "10d4549e3330bd6430d4a272a5dc140143989484"
45
+ "gitHead": "b1e5bf0a9b6ae66b7e71f0b1d9b9461ded748c5e"
46
46
  }