From c3e3befc17102ee1754e1403193040b4f79fb2a7 Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Tue, 2 Aug 2022 18:04:00 +0500 Subject: [PATCH] feat: add public group to DB on seed --- api/src/model/Group.ts | 2 ++ api/src/utils/seedDB.ts | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/api/src/model/Group.ts b/api/src/model/Group.ts index 6341825..3185f44 100644 --- a/api/src/model/Group.ts +++ b/api/src/model/Group.ts @@ -3,6 +3,8 @@ import { GroupDetailsResponse } from '../controllers' import User, { IUser } from './User' const AutoIncrement = require('mongoose-sequence')(mongoose) +export const PUBLIC_GROUP_NAME = 'Public' + export interface GroupPayload { /** * Name of the group diff --git a/api/src/utils/seedDB.ts b/api/src/utils/seedDB.ts index 7bff3a6..a43b374 100644 --- a/api/src/utils/seedDB.ts +++ b/api/src/utils/seedDB.ts @@ -1,5 +1,5 @@ import Client from '../model/Client' -import Group from '../model/Group' +import Group, { PUBLIC_GROUP_NAME } from '../model/Group' import User from '../model/User' import Configuration, { ConfigurationType } from '../model/Configuration' @@ -31,6 +31,15 @@ export const seedDB = async (): Promise => { console.log(`DB Seed - Group created: ${GROUP.name}`) } + // Checking if 'Public' Group is already in the database + const publicGroupExist = await Group.findOne({ name: PUBLIC_GROUP.name }) + if (!publicGroupExist) { + const group = new Group(PUBLIC_GROUP) + await group.save() + + console.log(`DB Seed - Group created: ${PUBLIC_GROUP.name}`) + } + // Checking if user is already in the database let usernameExist = await User.findOne({ username: ADMIN_USER.username }) if (!usernameExist) { @@ -68,6 +77,13 @@ const GROUP = { name: 'AllUsers', description: 'Group contains all users' } + +const PUBLIC_GROUP = { + name: PUBLIC_GROUP_NAME, + description: + 'It is a special group that bypasses authentication for particular routes.' +} + const CLIENT = { clientId: 'clientID1', clientSecret: 'clientSecret'