Add isShortProject field to db

This commit is contained in:
Eeritvan
2026-05-16 20:28:59 +03:00
parent b1f93ce78f
commit c842a359e7
4 changed files with 35 additions and 5 deletions
+8 -3
View File
@@ -88,7 +88,7 @@ const findNonExistingStudents = async (studentNumbers) => {
const validateGroup = async (body) => {
if (!body) return 'POST body is missing'
const { name, topicId, configurationId, instructorId, studentIds } = body
const { name, topicId, configurationId, instructorId, studentIds, isShortProject } = body
if (isNil(name) || typeof name !== 'string') return 'name is missing'
if (isNil(topicId) || typeof topicId !== 'number') return 'topicId is missing'
@@ -119,6 +119,10 @@ const validateGroup = async (body) => {
return `Instructor user ${instructorId} does not exist`
}
if (isNil(isShortProject) || typeof isShortProject !== 'boolean') {
return 'Project length is missing'
}
const nonExistingStudents = await findNonExistingStudents(studentIds)
if (nonExistingStudents.length > 0) {
return nonExistingStudents.length === 1
@@ -160,7 +164,7 @@ router.post('/', checkAdmin, async (req, res) => {
return res.status(400).json({ error: validationError })
}
const { name, topicId, configurationId, instructorId, studentIds } = req.body
const { name, topicId, configurationId, instructorId, studentIds, isShortProject } = req.body
// Wrap group creation and group_students join table setting in a transaction
// so that the group is not created if a foreign key violation occurs
@@ -178,7 +182,8 @@ router.post('/', checkAdmin, async (req, res) => {
name,
topicId,
configurationId,
instructorId: instructorId || null
instructorId: instructorId || null,
isShortProject,
},
options
)
@@ -0,0 +1,19 @@
'use strict'
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn(
'groups',
'is_short_project',
{
type: Sequelize.BOOLEAN,
defaultValue: false,
allowNull: false
}
)
},
// eslint-disable-next-line no-unused-vars
down: async (queryInterface, Sequelize) => {
await queryInterface.removeColumn('groups', 'is_short_project')
}
}
+6 -1
View File
@@ -6,7 +6,12 @@ module.exports = (sequelize, Sequelize) => {
autoIncrement: true,
primaryKey: true
},
name: Sequelize.STRING
name: Sequelize.STRING,
isShortProject: {
type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: false
}
},
{
underscored: true
@@ -84,13 +84,14 @@ const saveGroup = async (event, props) => {
})
try {
const isShortProject = projectLength === 'short'
const createdGroup = await groupManagementService.create({
name: groupName,
topicId: groupTopicID,
configurationId: groupConfigurationID,
instructorId: groupInstructor ? groupInstructor.student_number : '',
studentIds: splitStudents,
projectLength: projectLength,
isShortProject: isShortProject,
})
props.createGroupSuccsess(createdGroup)
props.onInstructorChange(null)