Skip to content
Open
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
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"license": "MIT",
"dependencies": {
"@hapi/joi": "^17.1.0",
"bcrypt": "^4.0.1",
"bcrypt": "^3.0.8",
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
Expand Down
11 changes: 10 additions & 1 deletion src/models/schema/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ module.exports = (sequelize, DataTypes) => {
primaryKey: true,
},
// This must be provided if editable is false
defaultValue: { type: DataTypes.TEXT },
defaultValue: {
type: DataTypes.TEXT,
validation: {
defaultValueValidation(editable) {
if (editable === false && this.defaultValue !== null) throw new Error('defaultValue validation Error');
},
},


},
editable: {
type: DataTypes.BOOLEAN,
defaultValue: false,
Expand Down
5 changes: 5 additions & 0 deletions src/models/schema/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ module.exports = (sequelize, DataTypes) => {
labId: {
type: DataTypes.UUID,
references: { model: 'Lab', key: 'id' },
Validation: {
labIdValidation(isDraft) {
if (isDraft === false && this.labId !== null) throw new Error('LabId validation failed');
},
},
},
itemSetId: {
type: DataTypes.UUID,
Expand Down
32 changes: 31 additions & 1 deletion src/models/schema/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,40 @@ module.exports = (sequelize, DataTypes) => {
references: { model: 'Supervisor', key: 'id' },
},
reason: { type: DataTypes.TEXT },
declineReason: { type: DataTypes.TEXT },
declineReason: {
type: DataTypes.TEXT,
Validation: {
declineReasonValidation(status) {
const nNullList = ['DECLINED', 'INVALIDATED'];
const nullList = ['REQUESTED', 'ACCEPTED'];

nNullList.forEach((item) => {
if (status.type === item && this.declineReason === null) throw new Error('Decline Reason Validation Error!');
});

nullList.forEach((item) => {
if (status.type === item && this.returnedDate !== null) throw new Error('Decline Reason Validation Error!');
});
},
},
},
supervisorToken: {
type: DataTypes.UUID,
unique: 'supervisor_token',
Validation: {
supervisorTokenValidation(status) {
const nNullList = ['REQUESTED', 'ACCEPTED'];
const nullList = ['DECLINED', 'INVALIDATED'];

nNullList.forEach((item) => {
if (status.type === item && this.supervisorToken === null) throw new Error('Supervisor Token Validation Error!');
});

nullList.forEach((item) => {
if (status.type === item && this.supervisorToken !== null) throw new Error('Supervisor Token Validation Error!');
});
},
},
},
status: {
type: DataTypes.ENUM('REQUESTED', 'ACCEPTED', 'DECLINED', 'INVALIDATED'),
Expand Down
51 changes: 48 additions & 3 deletions src/models/schema/request_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,54 @@ module.exports = (sequelize, DataTypes) => {
primaryKey: true,
references: { model: 'Request', key: 'id' },
},
returnedDate: { type: DataTypes.DATE },
dueDate: { type: DataTypes.DATE },
borrowedDate: { type: DataTypes.DATE },
returnedDate: {
type: DataTypes.DATE,
Validation: {
returnedDateValidation(status) {
const nNullList = ['PENDING', 'BORROWED', 'REJECTED'];
const nullList = ['RETURNED', 'EXPIRED'];
nNullList.forEach((item) => {
if (status.type === item && this.returnedDate !== null) throw new Error('Returned Date Validation Error!');
});

nullList.forEach((item) => {
if (status.type === item && this.returnedDate === null) throw new Error('Returned Date Validation Error!');
});
},
},
},
dueDate: {
type: DataTypes.DATE,
Validation: {
dueDateValidation(status) {
const nNullList = ['PENDING', 'REJECTED'];
const nullList = ['RETURNED', 'BORROWED', 'EXPIRED'];
nNullList.forEach((item) => {
if (status.type === item && this.dueDate !== null) throw new Error('Due Date Validation Error!');
});

nullList.forEach((item) => {
if (status.type === item && this.dueDate === null) throw new Error('Due Date Validation Error!');
});
},
},
},
borrowedDate: {
type: DataTypes.DATE,
Validation: {
borrowedDateValidation(status) {
const nNullList = ['PENDING', 'REJECTED'];
const nullList = ['RETURNED', 'BORROWED', 'EXPIRED'];
nNullList.forEach((item) => {
if (status.type === item && this.borrowedDate !== null) throw new Error('Borrowed Date Validation Error!');
});

nullList.forEach((item) => {
if (status.type === item && this.borrowedDate === null) throw new Error('Borrowed Date Validation Error!');
});
},
},
},
status: {
type: DataTypes.ENUM('PENDING', 'BORROWED', 'RETURNED', 'REJECTED', 'EXPIRED'),
defaultValue: 'PENDING',
Expand Down