refactor: expose api for loading demo project

This commit is contained in:
Carlos Valente
2024-11-22 21:43:13 +01:00
committed by Carlos Valente
parent a518dc4882
commit 7bf90d669a
4 changed files with 31 additions and 3 deletions
@@ -192,6 +192,25 @@ export async function loadProject(req: Request, res: Response<MessageResponse |
}
}
/**
* Loads the demo project
*/
export async function loadDemo(req: Request, res: Response<MessageResponse | ErrorResponse>) {
try {
const projectName = await projectService.loadDemoProject();
res.status(201).send({
message: `Loaded demo project: ${projectName}`,
});
} catch (error) {
const message = getErrorMessage(error);
if (message.startsWith('Project file')) {
return res.status(403).send({ message });
}
res.status(500).send({ message });
}
}
/**
* Duplicates a project file.
* Receives the original project filename (`filename`) from the request parameters
+2
View File
@@ -6,6 +6,7 @@ import {
deleteProjectFile,
duplicateProjectFile,
listProjects,
loadDemo,
loadProject,
patchPartialProjectFile,
postProjectFile,
@@ -36,6 +37,7 @@ router.post('/quick', validateQuickProject, quickProjectFile);
router.get('/all', listProjects);
router.post('/load', validateFilenameBody, loadProject);
router.post('/demo', loadDemo);
router.post('/:filename/duplicate', validateFilenameParam, validateNewFilenameBody, duplicateProjectFile);
router.put('/:filename/rename', validateFilenameParam, validateNewFilenameBody, renameProjectFile);
router.delete('/:filename', validateFilenameParam, deleteProjectFile);