mirror of
https://github.com/UniversityOfHelsinkiCS/ohtuilmo.git
synced 2026-10-12 19:03:41 +03:00
Add isShortProject field to db
This commit is contained in:
@@ -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,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)
|
||||
|
||||
Reference in New Issue
Block a user