mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 15:58:38 +01:00
add dashboard
This commit is contained in:
23
dashboard/server/api/project/create.post.ts
Normal file
23
dashboard/server/api/project/create.post.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ProjectModel, TProject } from "@schema/ProjectSchema";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const body = await readBody(event);
|
||||
|
||||
const newProjectName = body.name;
|
||||
|
||||
if (!newProjectName) return setResponseStatus(event, 400, 'ProjectName too short');
|
||||
if (newProjectName.length < 2) return setResponseStatus(event, 400, 'ProjectName too short');
|
||||
|
||||
const userData = getRequestUser(event);
|
||||
if (!userData?.logged) return setResponseStatus(event, 400, 'NotLogged');
|
||||
|
||||
const existingUserProjects = await ProjectModel.countDocuments({ owner: userData.id });
|
||||
if (existingUserProjects == 3) return setResponseStatus(event, 400, 'Already have 3 projects');
|
||||
|
||||
const newProject = new ProjectModel({ owner: userData.id, name: newProjectName });
|
||||
const saved = await newProject.save();
|
||||
|
||||
return saved.toJSON() as TProject;
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user