feat: quick project wizard

This commit is contained in:
Carlos Valente
2024-10-26 21:51:31 +02:00
committed by Carlos Valente
parent 27f99b4c87
commit ed2efe183b
17 changed files with 344 additions and 36 deletions
+26 -11
View File
@@ -1,4 +1,4 @@
import { DatabaseModel, ErrorResponse, MessageResponse, ProjectData, ProjectFileListResponse } from 'ontime-types';
import { DatabaseModel, ErrorResponse, MessageResponse, ProjectFileListResponse } from 'ontime-types';
import { getErrorMessage } from 'ontime-utils';
import type { Request, Response } from 'express';
@@ -30,17 +30,17 @@ export async function patchPartialProjectFile(req: Request, res: Response<Databa
* or a 500 status with an error message in case of an exception.
*/
export async function createProjectFile(req: Request, res: Response<{ filename: string } | ErrorResponse>) {
const newProjectData: ProjectData = {
title: req.body?.title ?? '',
description: req.body?.description ?? '',
publicUrl: req.body?.publicUrl ?? '',
publicInfo: req.body?.publicInfo ?? '',
backstageUrl: req.body?.backstageUrl ?? '',
backstageInfo: req.body?.backstageInfo ?? '',
};
try {
const newFileName = await projectService.createProject(req.body.filename, newProjectData);
const newFileName = await projectService.createProject(req.body.filename, {
project: {
title: req.body?.title ?? '',
description: req.body?.description ?? '',
publicUrl: req.body?.publicUrl ?? '',
publicInfo: req.body?.publicInfo ?? '',
backstageUrl: req.body?.backstageUrl ?? '',
backstageInfo: req.body?.backstageInfo ?? '',
},
});
res.status(200).send({
filename: newFileName,
@@ -51,6 +51,21 @@ export async function createProjectFile(req: Request, res: Response<{ filename:
}
}
/**
* Creates and loads a new project with partial DataBase data
*/
export async function quickProjectFile(req: Request, res: Response<{ filename: string } | ErrorResponse>) {
try {
const filename = await projectService.createProject(req.body.project.title, req.body);
res.status(200).send({
filename,
});
} catch (error) {
const message = getErrorMessage(error);
res.status(500).send({ message });
}
}
/**
* Allows downloading of current project file
*/
+3
View File
@@ -10,6 +10,7 @@ import {
patchPartialProjectFile,
postProjectFile,
projectDownload,
quickProjectFile,
renameProjectFile,
} from './db.controller.js';
import { uploadProjectFile } from './db.middleware.js';
@@ -19,6 +20,7 @@ import {
validateFilenameBody,
validateFilenameParam,
validateNewFilenameBody,
validateQuickProject,
} from './db.validation.js';
export const router = express.Router();
@@ -29,6 +31,7 @@ router.post('/upload', uploadProjectFile, postProjectFile);
router.patch('/', validatePatchProject, patchPartialProjectFile);
router.post('/new', validateFilenameBody, validateNewProject, createProjectFile);
router.post('/quick', validateQuickProject, quickProjectFile);
router.get('/all', listProjects);
@@ -22,6 +22,28 @@ export const validateNewProject = [
},
];
/**
* @description Validates request for a quick project.
*/
export const validateQuickProject = [
// Project fields
body('project.title').isString().trim(),
// Settings fields
body('settings.timeFormat').optional().isIn(['12', '24']),
body('settings.language').optional().isString().trim(),
// ViewSettings fields
body('viewSettings.freezeEnd').optional().isBoolean(),
body('viewSettings.endMessage').optional().isString().trim(),
(req: Request, res: Response, next: NextFunction) => {
const errors = validationResult(req);
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
next();
},
];
/**
* @description Validates request for pathing data in the project.
*/