Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/services/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,16 @@ module.exports = class AccountHelper {
{ attributes: ['id'] }
)
let defaultOrgId = defaultOrg.id
const modelName = await userQueries.getModelName()

let validationData = await entityTypeQueries.findUserEntityTypesAndEntities({
status: 'ACTIVE',
organization_id: {
[Op.in]: [user.organization_id, defaultOrgId],
},
model_names: { [Op.contains]: [modelName] },
})

const prunedEntities = removeDefaultOrgEntityTypes(validationData, user.organization_id)
user = utils.processDbResponse(user, prunedEntities)

Expand Down
2 changes: 2 additions & 0 deletions src/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ module.exports = class UserHelper {
organization_id: {
[Op.in]: [orgId, defaultOrgId],
},
model_names: { [Op.contains]: [await userQueries.getModelName()] },
}
let validationData = await entityTypeQueries.findUserEntityTypesAndEntities(filter)
const prunedEntities = removeDefaultOrgEntityTypes(validationData)
Expand Down Expand Up @@ -194,6 +195,7 @@ module.exports = class UserHelper {
organization_id: {
[Op.in]: [user.organization_id, defaultOrgId],
},
model_names: { [Op.contains]: [await userQueries.getModelName()] },
})
const prunedEntities = removeDefaultOrgEntityTypes(validationData, user.organization_id)
const processDbResponse = utils.processDbResponse(user, prunedEntities)
Expand Down
38 changes: 30 additions & 8 deletions src/validators/v1/entity-type.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* name : validators/v1/entity-types.js
* name : validators/v1/entity-type.js
* author : Aman Gupta
* Date : 04-Nov-2021
* Description : Validations of user entities controller
Expand All @@ -11,7 +11,7 @@ module.exports = {
.trim()
.notEmpty()
.withMessage('value field is empty')
.matches(/^[A-Za-z]+$/)
.matches(/^[A-Za-z_]+$/)
.withMessage('value is invalid, must not contain spaces')

req.checkBody('label')
Expand All @@ -28,6 +28,15 @@ module.exports = {
.matches(/^[A-Za-z]+$/)
.withMessage('data_type is invalid, must not contain spaces')

req.checkBody('model_names')
.isArray()
.notEmpty()
.withMessage('model_names must be an array with at least one element')

req.checkBody('model_names.*')
.isIn(['Session', 'MentorExtension', 'UserExtension'])
.withMessage('model_names must be in Session,MentorExtension,UserExtension')

req.checkBody('allow_filtering').optional().isEmpty().withMessage('allow_filtering is not allowed in create')
},

Expand All @@ -49,24 +58,37 @@ module.exports = {
.matches(/^[A-Z]+$/)
.withMessage('status is invalid, must be in all caps')

req.checkBody('deleted').optional().isBoolean().withMessage('deleted is invalid')
req.checkBody('allow_filtering').optional().isEmpty().withMessage('allow_filtering is not allowed in create')

req.checkBody('data_type')
.optional()
.trim()
.notEmpty()
.withMessage('data_type field is empty')
.matches(/^[A-Za-z]+$/)
.withMessage('data_type is invalid, must not contain spaces')

req.checkBody('allow_filtering').optional().isEmpty().withMessage('allow_filtering is not allowed in create')
req.checkBody('model_names')
.isArray()
.notEmpty()
.withMessage('model_names must be an array with at least one element')

req.checkBody('model_names.*')
.isIn(['Session', 'MentorExtension', 'UserExtension'])
.withMessage('model_names must be in Session,MentorExtension,UserExtension')
},

read: (req) => {
console.log()
if (req.query.data_type) {
req.checkQuery('data_type')
if (req.query.type) {
req.checkQuery('type')
.trim()
.notEmpty()
.withMessage('data_type field is empty')
.withMessage('type field is empty')
.matches(/^[A-Za-z]+$/)
.withMessage('type is invalid, must not contain spaces')

req.checkQuery('deleted').optional().isBoolean().withMessage('deleted is invalid')

req.checkQuery('status')
.optional()
.trim()
Expand Down
27 changes: 21 additions & 6 deletions src/validators/v1/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ module.exports = {
.matches(/^[A-Za-z0-9 ]+$/)
.withMessage('label is invalid')

req.checkBody('type')
.trim()
req.checkBody('entity_type_id')
.notEmpty()
.withMessage('type field is empty')
.matches(/^[A-Za-z]+$/)
.withMessage('type is invalid, must not contain spaces')
.withMessage('entity_type_id field is empty')
.isNumeric()
.withMessage('entity_type_id is invalid, must be numeric')
},

update: (req) => {
Expand Down Expand Up @@ -55,7 +54,23 @@ module.exports = {
.withMessage('type is invalid, must not contain spaces')
},

read: (req) => {},
read: (req) => {
req.checkQuery('id')
.trim()
.optional()
.notEmpty()
.withMessage('id param is empty')
.isNumeric()
.withMessage('id param is invalid, must be an integer')

req.checkQuery('value')
.trim()
.optional()
.notEmpty()
.withMessage('value field is empty')
.matches(/^[A-Za-z0-9 ]+$/)
.withMessage('value is invalid, must not contain spaces')
},

delete: (req) => {
req.checkParams('id').notEmpty().withMessage('id param is empty')
Expand Down