adminmate-express-mongoose 1.2.3 → 1.2.7

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.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Adminmate (Express.js + Mongoose)
2
+
3
+ Adminmate is a powerful & flexible back-office solution build for small to big teams. ✌️
4
+
5
+ It provides an extremely flexible API developed in NodeJS that communicate with a powerful frontend back-office we host.
6
+
7
+ As the security & privacy of your data is our main focus, the Data API is host by yourself and secured by your own credentials.
8
+
9
+ ## Getting started
10
+
11
+ [https://adminmate.io](https://adminmate.io)
12
+
13
+ ## Databases compatibility
14
+
15
+ Adminmate is compatible with the most famous database systems like **MySQL**, **PostgreSQL**, **SQLite** and **MongoDB**. We are working hard on adding more soon!
16
+
17
+ ## Features
18
+
19
+ Adminmate comes with all the features you need for your back-office:
20
+ * **Data**: Data Explorer, CRUD, Filters, Segments, Actions
21
+ * **Dashboards & Charts**: Unlimited Dashboards & Charts
22
+ * **Collaboration**: Powerful collaboration tool
23
+ * **Activity**: Track everything that happening on your database data
24
+ * **Access Control**: Team-based Access Control
25
+
26
+ ### Data explorer
27
+
28
+ ![Alt text](https://adminmate.io/github/list-screen.svg)
29
+
30
+ ### Dashboards & Charts
31
+
32
+ ![Alt text](https://adminmate.io/github/homepage-screen.svg)
33
+
34
+ ### Activity
35
+
36
+ ![Alt text](https://adminmate.io/github/activity-screen.svg)
37
+
38
+ ## Who are the contributors ?
39
+
40
+ Adminmate is a bootstrapped project tailored by **Marc Delalonde** and aims to stay an *independent project, driven by the community*.
package/index.js CHANGED
@@ -15,10 +15,15 @@ const { customQuery } = require('./src/controllers/model-query');
15
15
 
16
16
  const Adminmate = ({ projectId, secretKey, authKey, masterPassword, models, charts, authorizedIps }) => {
17
17
  const api = {
18
+ // App config
19
+ getAppConfig: fnHelper.getAppConfig,
20
+
18
21
  // General
19
22
  getModelProperties: fnHelper.getModelProperties,
20
23
  getModelRealname: fnHelper.getModelRealname,
21
24
  getModelRelationships: fnHelper.getModelAssociations,
25
+ getModelPrimaryKeys: fnHelper.getModelPrimaryKeys,
26
+ getModelWhereClause: fnHelper.getModelWhereClause,
22
27
 
23
28
  // CRUD
24
29
  modelGetAll: getAll,
package/jest.config.js CHANGED
@@ -1,5 +1,4 @@
1
1
  module.exports = {
2
- testEnvironment: 'node',
3
2
  projects: [
4
3
  {
5
4
  displayName: 'mongodb',
package/package.json CHANGED
@@ -1,19 +1,29 @@
1
1
  {
2
2
  "name": "adminmate-express-mongoose",
3
- "version": "1.2.3",
3
+ "version": "1.2.7",
4
4
  "description": "Adminmate Express/Mongoose connector",
5
5
  "author": "Marc Delalonde",
6
+ "homepage": "http://adminmate.io",
7
+ "license": "GPL-3.0",
8
+ "keywords": [
9
+ "adminmate",
10
+ "admin",
11
+ "panel",
12
+ "interface",
13
+ "back-office",
14
+ "mongodb",
15
+ "mongoose"
16
+ ],
6
17
  "scripts": {
7
18
  "start": "node ./index",
8
- "test": "jest --runInBand",
9
- "reset-db": "node migration.js"
19
+ "test": "jest --runInBand"
10
20
  },
11
21
  "repository": {
12
22
  "type": "git",
13
23
  "url": "https://github.com/Adminmate/adminmate-express-mongoose.git"
14
24
  },
15
25
  "dependencies": {
16
- "adminmate-express-core": "^1.1.4",
26
+ "adminmate-express-core": "^1.1.6",
17
27
  "lodash": "^4.17.21",
18
28
  "moment": "^2.29.1",
19
29
  "mongoose": "^5.9.7",
@@ -12,41 +12,44 @@ module.exports = async (currentModel, data) => {
12
12
 
13
13
  const toSum = data.field && data.operation === 'sum' ? `$${data.field}` : 1;
14
14
 
15
+ // To set the max date
16
+ const toDate = data.to ? moment(data.to) : moment();
17
+
15
18
  let matchReq = {};
16
19
  let groupFormat = '';
17
20
 
18
21
  // Day timeframe
19
22
  if (data.timeframe === 'day') {
20
- const startOfCurrentDay = moment().startOf('day');
23
+ const startOfCurrentDay = toDate.startOf('day');
21
24
  matchReq = {
22
- '$gte': new Date(startOfCurrentDay.subtract(30, 'day').startOf('day').format()),
25
+ '$gte': new Date(startOfCurrentDay.clone().subtract(30, 'day').startOf('day').format()),
23
26
  '$lt': new Date(startOfCurrentDay.format())
24
27
  };
25
28
  groupFormat = '%Y-%m-%d';
26
29
  }
27
30
  // Week timeframe
28
31
  else if (data.timeframe === 'week') {
29
- const startOfCurrentWeek = moment().startOf('week');
32
+ const startOfCurrentWeek = toDate.startOf('week');
30
33
  matchReq = {
31
- '$gte': new Date(startOfCurrentWeek.subtract(26, 'week').startOf('week').format()),
34
+ '$gte': new Date(startOfCurrentWeek.clone().subtract(26, 'week').startOf('week').format()),
32
35
  '$lt': new Date(startOfCurrentWeek.format())
33
36
  };
34
37
  groupFormat = '%V';
35
38
  }
36
39
  // Month timeframe
37
40
  else if (data.timeframe === 'month') {
38
- const startOfCurrentMonth = moment().startOf('month');
41
+ const startOfCurrentMonth = toDate.startOf('month');
39
42
  matchReq = {
40
- '$gte': new Date(startOfCurrentMonth.subtract(12, 'month').startOf('month').format()),
43
+ '$gte': new Date(startOfCurrentMonth.clone().subtract(12, 'month').startOf('month').format()),
41
44
  '$lt': new Date(startOfCurrentMonth.format())
42
45
  };
43
46
  groupFormat = '%m';
44
47
  }
45
48
  // Year timeframe
46
49
  else if (data.timeframe === 'year') {
47
- const startOfCurrentYear = moment().startOf('year');
50
+ const startOfCurrentYear = toDate.startOf('year');
48
51
  matchReq = {
49
- '$gte': new Date(startOfCurrentYear.subtract(8, 'year').startOf('year').format()),
52
+ '$gte': new Date(startOfCurrentYear.clone().subtract(8, 'year').startOf('year').format()),
50
53
  '$lt': new Date(startOfCurrentYear.format())
51
54
  };
52
55
  groupFormat = '%Y';
@@ -82,8 +85,8 @@ module.exports = async (currentModel, data) => {
82
85
 
83
86
  // Day timeframe
84
87
  if (data.timeframe === 'day') {
85
- for (let i = 0; i < 30; i++) {
86
- const currentDate = moment().subtract(i, 'day');
88
+ for (let i = 1; i <= 30; i++) {
89
+ const currentDate = toDate.clone().subtract(i, 'day').startOf('day');
87
90
  const countForTheTimeframe = _.find(repartitionData, { key: currentDate.format('YYYY-MM-DD') });
88
91
  formattedData.push({
89
92
  key: currentDate.format('DD/MM'),
@@ -93,9 +96,8 @@ module.exports = async (currentModel, data) => {
93
96
  }
94
97
  // Week timeframe
95
98
  else if (data.timeframe === 'week') {
96
- for (let i = 0; i < 26; i++) {
97
- const currentWeek = moment().subtract(i, 'week');
98
-
99
+ for (let i = 1; i <= 26; i++) {
100
+ const currentWeek = toDate.clone().subtract(i, 'week').startOf('week');
99
101
  const countForTheTimeframe = _.find(repartitionData, { key: currentWeek.format('WW') });
100
102
  formattedData.push({
101
103
  key: currentWeek.startOf('week').format('DD/MM'),
@@ -105,9 +107,8 @@ module.exports = async (currentModel, data) => {
105
107
  }
106
108
  // Month timeframe
107
109
  else if (data.timeframe === 'month') {
108
- for (let i = 0; i < 12; i++) {
109
- const currentMonth = moment().subtract(i, 'month');
110
-
110
+ for (let i = 1; i <= 12; i++) {
111
+ const currentMonth = toDate.clone().subtract(i, 'month').startOf('month');
111
112
  const countForTheTimeframe = _.find(repartitionData, { key: currentMonth.format('MM') });
112
113
  formattedData.push({
113
114
  key: currentMonth.startOf('month').format('MMM'),
@@ -117,9 +118,8 @@ module.exports = async (currentModel, data) => {
117
118
  }
118
119
  // Year timeframe
119
120
  else if (data.timeframe === 'year') {
120
- for (let i = 0; i < 8; i++) {
121
- const currentYear = moment().subtract(i, 'year');
122
-
121
+ for (let i = 1; i <= 8; i++) {
122
+ const currentYear = toDate.clone().subtract(i, 'year').startOf('year');
123
123
  const countForTheTimeframe = _.find(repartitionData, { key: currentYear.format('YYYY') });
124
124
  formattedData.push({
125
125
  key: currentYear.startOf('year').format('YYYY'),
@@ -3,8 +3,8 @@ const fnHelper = require('../helpers/functions');
3
3
 
4
4
  module.exports.getAutocomplete = async (req, res) => {
5
5
  const modelName = req.params.model;
6
- const search = (req.body.search || '').trim();
7
- const refFields = req.body.refFields;
6
+ const search = (req.query.s || '').trim();
7
+ const refFields = req.headers['am-ref-fields'] || {};
8
8
  const maxItem = 10;
9
9
 
10
10
  const currentModel = fnHelper.getModelObject(modelName);
@@ -3,16 +3,16 @@ const fnHelper = require('../helpers/functions');
3
3
 
4
4
  module.exports.getAll = async (req, res) => {
5
5
  const modelName = req.params.model;
6
- const segment = req.body.segment;
7
- const search = (req.body.search || '').trim();
8
- const filters = req.body.filters;
9
- const fieldsToFetch = req.body.fields || [];
10
- const refFields = req.body.refFields;
11
- const fieldsToSearchIn = req.body.fieldsToSearchIn || [];
12
- const page = parseInt(req.body.page || 1);
6
+ const segment = req.query.segment;
7
+ const search = (req.query.search || '').trim();
8
+ const filters = req.query.filters;
9
+ const fieldsToFetch = req.headers['am-model-fields'] || [];
10
+ const refFields = req.headers['am-ref-fields'] || {};
11
+ const fieldsToSearchIn = req.query.fieldsToSearchIn || [];
12
+ const page = parseInt(req.query.page || 1);
13
13
  const nbItemPerPage = 10;
14
14
  const defaultOrdering = [ ['_id', 'DESC'] ];
15
- const order = req.body.order || null;
15
+ const order = req.query.order || null;
16
16
 
17
17
  const currentModel = fnHelper.getModelObject(modelName);
18
18
  if (!currentModel) {
@@ -4,7 +4,8 @@ const fnHelper = require('../helpers/functions');
4
4
  module.exports.getOne = async (req, res) => {
5
5
  const modelName = req.params.model;
6
6
  const modelItemId = req.params.id;
7
- const refFields = req.body.refFields || {};
7
+ const fieldsToFetch = req.headers['am-model-fields'] || [];
8
+ const refFields = req.headers['am-ref-fields'] || {};
8
9
 
9
10
  const currentModel = fnHelper.getModelObject(modelName);
10
11
  if (!currentModel) {
@@ -13,14 +14,14 @@ module.exports.getOne = async (req, res) => {
13
14
 
14
15
  const keys = fnHelper.getModelProperties(currentModel);
15
16
  const defaultFieldsToFetch = keys.map(key => key.path);
16
- const fieldsToFetch = req.body.fields ? req.body.fields : defaultFieldsToFetch;
17
+ const fieldsToFetchSafe = Array.isArray(fieldsToFetch) && fieldsToFetch.length ? fieldsToFetch : defaultFieldsToFetch;
17
18
 
18
19
  // Build ref fields for the model (for mongoose population purpose)
19
- const fieldsToPopulate = fnHelper.getFieldsToPopulate(keys, fieldsToFetch, refFields);
20
+ const fieldsToPopulate = fnHelper.getFieldsToPopulate(keys, fieldsToFetchSafe, refFields);
20
21
 
21
22
  let data = await currentModel
22
23
  .findById(modelItemId)
23
- .select(fieldsToFetch)
24
+ .select(fieldsToFetchSafe)
24
25
  .populate(fieldsToPopulate)
25
26
  .lean()
26
27
  .catch(e => {
@@ -3,6 +3,8 @@ const { serializeError } = require('serialize-error');
3
3
  const _ = require('lodash');
4
4
  const moment = require('moment');
5
5
 
6
+ const pjson = require('../../package.json');
7
+
6
8
  const getModelProperties = model => {
7
9
  let modelFields = [];
8
10
  const modelProps = model.schema.paths;
@@ -354,6 +356,14 @@ module.exports.constructSearch = (search, fieldsToSearchIn, fieldsToPopulate = [
354
356
  return params;
355
357
  };
356
358
 
359
+ module.exports.getModelWhereClause = (model, idsArray) => {
360
+ return { _id: idsArray };
361
+ };
362
+
363
+ module.exports.getModelPrimaryKeys = model => {
364
+ return ['_id'];
365
+ };
366
+
357
367
  module.exports.getModelAssociations = model => {
358
368
  // Get current model mongoose realname
359
369
  const currentModelRealName = getModelRealname(model);
@@ -462,4 +472,11 @@ module.exports.getCleanOrderStructure = orderConfig => {
462
472
  order[oc[0]] = oc[1];
463
473
  });
464
474
  return order;
475
+ };
476
+
477
+ module.exports.getAppConfig = () => {
478
+ return {
479
+ package: pjson.name,
480
+ version: pjson.version
481
+ };
465
482
  };
package/database.js DELETED
@@ -1,16 +0,0 @@
1
- const mongoose = require('mongoose');
2
-
3
- const User = require('./models/user');
4
- const Car = require('./models/car');
5
- const Blocked = require('./models/blocked');
6
-
7
- const connectDb = () => {
8
- return mongoose.connect('mongodb://localhost:27017/node-express-mongodb-server', {
9
- useNewUrlParser: true,
10
- useUnifiedTopology: true
11
- });
12
- };
13
-
14
- const models = { User, Car, Blocked };
15
-
16
- module.exports = { models, connectDb };
package/migration.js DELETED
@@ -1,234 +0,0 @@
1
- const { models, connectDb } = require('./database');
2
-
3
- connectDb().then(async () => {
4
- console.log('MongoDB connected');
5
-
6
- // Remove all entries
7
- await Promise.all([
8
- models.User.deleteMany({}),
9
- models.Car.deleteMany({}),
10
- models.Blocked.deleteMany({})
11
- ]);
12
-
13
- // Create users
14
- await models.User.insertMany([
15
- {
16
- _id: '5cd5308e695db945d3cc81a1',
17
- firstname: 'John',
18
- lastname: 'Doe',
19
- birthdate: '2021-04-02T00:00:00.000Z',
20
- rating: 4,
21
- createdAt: '2021-04-02T00:00:00.000Z',
22
- updatedAt: '2021-04-02T00:00:00.000Z'
23
- },
24
- {
25
- _id: '5cd5308e695db945d3cc81a2',
26
- firstname: 'Maria',
27
- lastname: 'Doe',
28
- birthdate: '2021-04-02T00:00:00.000Z',
29
- rating: 5,
30
- createdAt: '2021-04-02T00:00:00.000Z',
31
- updatedAt: '2021-04-02T00:00:00.000Z'
32
- }
33
- ]);
34
-
35
- // Create cars
36
- await models.Car.insertMany([
37
- {
38
- _id: '5cd5308e695db945d3cc81b1',
39
- name: 'Porsche 356',
40
- manufacturer: 'Porsche',
41
- year: 1948,
42
- user_id: '5cd5308e695db945d3cc81a1',
43
- createdAt: "2021-04-02T00:00:00.000Z",
44
- updatedAt: "2021-04-02T00:00:00.000Z"
45
- },
46
- {
47
- _id: '5cd5308e695db945d3cc81b2',
48
- name: 'Porsche 550',
49
- manufacturer: 'Porsche',
50
- year: 1953,
51
- user_id: '5cd5308e695db945d3cc81a2',
52
- createdAt: "2021-04-02T00:00:00.000Z",
53
- updatedAt: "2021-04-02T00:00:00.000Z"
54
- },
55
- {
56
- _id: '5cd5308e695db945d3cc81b3',
57
- name: 'Porsche 911',
58
- manufacturer: 'Porsche',
59
- year: 1963,
60
- user_id: '5cd5308e695db945d3cc81a1',
61
- createdAt: "2021-04-02T00:00:00.000Z",
62
- updatedAt: "2021-04-02T00:00:00.000Z"
63
- },
64
- {
65
- _id: '5cd5308e695db945d3cc81b4',
66
- name: 'Porsche 904',
67
- manufacturer: 'Porsche',
68
- year: 1964,
69
- user_id: '5cd5308e695db945d3cc81a2',
70
- createdAt: "2021-04-02T00:00:00.000Z",
71
- updatedAt: "2021-04-02T00:00:00.000Z"
72
- },
73
- {
74
- _id: '5cd5308e695db945d3cc81b5',
75
- name: 'Porsche 906',
76
- manufacturer: 'Porsche',
77
- year: 1966,
78
- user_id: '5cd5308e695db945d3cc81a1',
79
- createdAt: "2021-04-02T00:00:00.000Z",
80
- updatedAt: "2021-04-02T00:00:00.000Z"
81
- },
82
- {
83
- _id: '5cd5308e695db945d3cc81b6',
84
- name: 'Porsche 908',
85
- manufacturer: 'Porsche',
86
- year: 1968,
87
- user_id: '5cd5308e695db945d3cc81a2',
88
- createdAt: "2021-04-02T00:00:00.000Z",
89
- updatedAt: "2021-04-02T00:00:00.000Z"
90
- },
91
- {
92
- _id: '5cd5308e695db945d3cc81b7',
93
- name: 'Porsche 914',
94
- manufacturer: 'Porsche',
95
- year: 1969,
96
- user_id: '5cd5308e695db945d3cc81a1',
97
- createdAt: "2021-04-02T00:00:00.000Z",
98
- updatedAt: "2021-04-02T00:00:00.000Z"
99
- },
100
- {
101
- _id: '5cd5308e695db945d3cc81b8',
102
- name: 'Porsche 917',
103
- manufacturer: 'Porsche',
104
- year: 1969,
105
- user_id: '5cd5308e695db945d3cc81a2',
106
- createdAt: "2021-04-02T00:00:00.000Z",
107
- updatedAt: "2021-04-02T00:00:00.000Z"
108
- },
109
- {
110
- _id: '5cd5308e695db945d3cc81b9',
111
- name: 'Porsche 924',
112
- manufacturer: 'Porsche',
113
- year: 1976,
114
- user_id: '5cd5308e695db945d3cc81a2',
115
- createdAt: "2021-04-02T00:00:00.000Z",
116
- updatedAt: "2021-04-02T00:00:00.000Z"
117
- },
118
- {
119
- _id: '5cd5308e695db945d3cc81c1',
120
- name: 'Porsche Macan',
121
- manufacturer: 'Porsche',
122
- year: 2014,
123
- user_id: '5cd5308e695db945d3cc81a2',
124
- createdAt: "2021-04-02T00:00:00.000Z",
125
- updatedAt: "2021-04-02T00:00:00.000Z"
126
- },
127
- {
128
- _id: '5cd5308e695db945d3cc81c2',
129
- name: 'Ferrari 212 Inter',
130
- manufacturer: 'Ferrari',
131
- year: 1951,
132
- user_id: '5cd5308e695db945d3cc81a1',
133
- createdAt: "2021-04-02T00:00:00.000Z",
134
- updatedAt: "2021-04-02T00:00:00.000Z"
135
- },
136
- {
137
- _id: '5cd5308e695db945d3cc81c3',
138
- name: 'Ferrari 250 MM',
139
- manufacturer: 'Ferrari',
140
- year: 1952,
141
- user_id: '5cd5308e695db945d3cc81a2',
142
- createdAt: "2021-04-02T00:00:00.000Z",
143
- updatedAt: "2021-04-02T00:00:00.000Z"
144
- },
145
- {
146
- _id: '5cd5308e695db945d3cc81c4',
147
- name: 'Ferrari 250 GT Coupé',
148
- manufacturer: 'Ferrari',
149
- year: 1954,
150
- user_id: '5cd5308e695db945d3cc81a1',
151
- createdAt: "2021-04-02T00:00:00.000Z",
152
- updatedAt: "2021-04-02T00:00:00.000Z"
153
- },
154
- {
155
- _id: '5cd5308e695db945d3cc81c5',
156
- name: 'Ferrari 250 GT Berlinetta SWB',
157
- manufacturer: 'Ferrari',
158
- year: 1959,
159
- user_id: '5cd5308e695db945d3cc81a2',
160
- createdAt: "2021-04-02T00:00:00.000Z",
161
- updatedAt: "2021-04-02T00:00:00.000Z"
162
- },
163
- {
164
- _id: '5cd5308e695db945d3cc81c6',
165
- name: 'Ferrari 250 GT 2+2',
166
- manufacturer: 'Ferrari',
167
- year: 1960,
168
- user_id: '5cd5308e695db945d3cc81a1',
169
- createdAt: "2021-04-02T00:00:00.000Z",
170
- updatedAt: "2021-04-02T00:00:00.000Z"
171
- },
172
- {
173
- _id: '5cd5308e695db945d3cc81c7',
174
- name: 'Ferrari 250 GTO',
175
- manufacturer: 'Ferrari',
176
- year: 1962,
177
- user_id: '5cd5308e695db945d3cc81a2',
178
- createdAt: "2021-04-02T00:00:00.000Z",
179
- updatedAt: "2021-04-02T00:00:00.000Z"
180
- },
181
- {
182
- _id: '5cd5308e695db945d3cc81c8',
183
- name: 'Ferrari 250 GT Lusso',
184
- manufacturer: 'Ferrari',
185
- year: 1962,
186
- user_id: '5cd5308e695db945d3cc81a1',
187
- createdAt: "2021-04-02T00:00:00.000Z",
188
- updatedAt: "2021-04-02T00:00:00.000Z"
189
- },
190
- {
191
- _id: '5cd5308e695db945d3cc81c9',
192
- name: 'Ferrari 488',
193
- manufacturer: 'Ferrari',
194
- year: 1969,
195
- user_id: '5cd5308e695db945d3cc81a2',
196
- createdAt: "2021-04-02T00:00:00.000Z",
197
- updatedAt: "2021-04-02T00:00:00.000Z"
198
- },
199
- {
200
- _id: '5cd5308e695db945d3cc81d1',
201
- name: 'Ferrari 275',
202
- manufacturer: 'Ferrari',
203
- year: 1964,
204
- user_id: '5cd5308e695db945d3cc81a2',
205
- createdAt: "2021-04-02T00:00:00.000Z",
206
- updatedAt: "2021-04-02T00:00:00.000Z"
207
- },
208
- {
209
- _id: '5cd5308e695db945d3cc81d2',
210
- name: 'Ferrari 250 LM',
211
- manufacturer: 'Ferrari',
212
- year: 1964,
213
- user_id: '5cd5308e695db945d3cc81a2',
214
- createdAt: "2021-04-02T00:00:00.000Z",
215
- updatedAt: "2021-04-02T00:00:00.000Z"
216
- }
217
- ]);
218
-
219
- // Create Blocked
220
- await models.Blocked.insertMany([
221
- {
222
- _id: '5cd5308e695db945d3cc81c1',
223
- blocked_id: '5cd5308e695db945d3cc81a1',
224
- blocked_model: 'User'
225
- },
226
- {
227
- _id: '5cd5308e695db945d3cc81c2',
228
- blocked_id: '5cd5308e695db945d3cc81b1',
229
- blocked_model: 'Car'
230
- }
231
- ]);
232
-
233
- console.log('Done!');
234
- });
package/models/blocked.js DELETED
@@ -1,17 +0,0 @@
1
- const mongoose = require('mongoose');
2
- const Schema = mongoose.Schema;
3
-
4
- const BlockedSchema = new Schema({
5
- blocked_id: {
6
- type: Schema.Types.ObjectId,
7
- required: true,
8
- refPath: 'blocked_model'
9
- },
10
- blocked_model: {
11
- type: String,
12
- required: true,
13
- enum: ['User', 'Car']
14
- }
15
- });
16
-
17
- module.exports = mongoose.model('Blocked', BlockedSchema, 'blocked');
package/models/car.js DELETED
@@ -1,26 +0,0 @@
1
- const mongoose = require('mongoose');
2
- const Schema = mongoose.Schema;
3
-
4
- const CarSchema = new Schema({
5
- user_id: {
6
- type: Schema.Types.ObjectId,
7
- ref: 'User'
8
- },
9
- name: {
10
- type: String
11
- },
12
- manufacturer: {
13
- type: String
14
- },
15
- year: {
16
- type: Number
17
- },
18
- createdAt: {
19
- type: Date
20
- },
21
- updatedAt: {
22
- type: Date
23
- }
24
- });
25
-
26
- module.exports = mongoose.model('Car', CarSchema, 'cars');
package/models/user.js DELETED
@@ -1,25 +0,0 @@
1
- const mongoose = require('mongoose');
2
- const Schema = mongoose.Schema;
3
-
4
- const UserSchema = new Schema({
5
- firstname: {
6
- type: String
7
- },
8
- lastname: {
9
- type: String
10
- },
11
- birthdate: {
12
- type: Date
13
- },
14
- rating: {
15
- type: Number
16
- },
17
- createdAt: {
18
- type: Date
19
- },
20
- updatedAt: {
21
- type: Date
22
- }
23
- });
24
-
25
- module.exports = mongoose.model('User', UserSchema, 'users');