Skip to content

Commit

Permalink
feat: user collection added (foyzulkarim#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
aninda052 committed Aug 28, 2023
1 parent 2cc513b commit 5decaf2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/src/modules/db/collections.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { ObjectId } = require('mongodb');
const { MongoManager } = require('./mongo');
const { baseDefaults } = require('./schemas/common');
const { collectionName:userCollectionName } = require('./schemas/user')

const insertItem = async (collection, item) => {
try {
Expand Down Expand Up @@ -117,4 +118,5 @@ const createCollectionObject = (collectionName) =>
module.exports = {
Video: createCollectionObject('videos'),
Role: createCollectionObject('roles'),
User: createCollectionObject(userCollectionName),
};
59 changes: 59 additions & 0 deletions server/src/modules/db/schemas/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { baseSchema, ensureCollection } = require('./common');


const collectionName = 'user';


const updateSchema = async (db) => {
const validator = {
$jsonSchema: {
bsonType: 'object',
additionalProperties: false,
required: [
'email',
'password',
...Object.keys(baseSchema),
],
properties: {
...baseSchema,
name: {
bsonType: 'string',
description: 'must be a string and is required',
},
email: {
bsonType: 'string',
description: 'must be a string and is required',
},
password: {
bsonType: 'string',
description: 'must be a string and is required',
},
isActive: {
bsonType: 'bool',
description: 'Whether the user is active',
},


},
},
};

const indexes = [
{
key: { name: 'text'},
name: 'name_index',
},
{
key: { email: 1 },
unique: true,
name: 'email_index',
}
];

await ensureCollection({ db, name:collectionName, validator, indexes });
};

module.exports = {
updateSchema,
collectionName,
};

0 comments on commit 5decaf2

Please sign in to comment.