generated from corrad-software/corrad-af-2024
Added API for creating folders.
Use POST request for creating folder. Folders are indexed in the database.
This commit is contained in:
parent
822d5e3ca4
commit
15c5919d8c
0
server/api/dms/folder.patch.js
Normal file
0
server/api/dms/folder.patch.js
Normal file
@ -1,4 +1,5 @@
|
|||||||
import { PrismaClient } from "@prisma/client";
|
import { PrismaClient } from "@prisma/client";
|
||||||
|
// import { readBody } from "h3";
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
@ -7,18 +8,57 @@ export default defineEventHandler( async (event) => {
|
|||||||
|
|
||||||
// const successMsg = "Hello from the backend";
|
// const successMsg = "Hello from the backend";
|
||||||
|
|
||||||
const body = readBody(event);
|
const body = await readBody(event);
|
||||||
|
|
||||||
if (!body) {
|
if (!body) {
|
||||||
return {
|
return {
|
||||||
status: 400,
|
status: 400,
|
||||||
message: "Body was not received"
|
message: "Body was not received"
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
status: 200,
|
|
||||||
message: "Body received successfully",
|
|
||||||
body: body
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
This is a sample of the expected body data structure:
|
||||||
|
{
|
||||||
|
cabinet_name: "Cabinet 1",
|
||||||
|
cabinet_parent_id: "", // NULL means its a root folder and has no parents.
|
||||||
|
cabinet_owner: "", // OPTIONAL
|
||||||
|
cabinet_sector: "", // Dunno??? Has a max length of 7 characters.
|
||||||
|
dp_id: "", // LEAVE NULL department ID. Foreign key. Is disabled for development purposes.
|
||||||
|
userID: "", // LEAVE NULL User ID. Foreign key. Is disabled for development purposes.
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// The following are functions to check the body data structure.
|
||||||
|
|
||||||
|
console.log(body.cabinet_name);
|
||||||
|
|
||||||
|
if (!body.cabinet_name || !body.cabinet_sector) {
|
||||||
|
return {
|
||||||
|
status: 400,
|
||||||
|
message: "cabinet_name and cabinet_sector are required"
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Checked body data.
|
||||||
|
const folderData = {
|
||||||
|
cb_name: body.cabinet_name,
|
||||||
|
cb_parent_id: body.cabinet_parent_id,
|
||||||
|
cb_owner: body.cabinet_owner,
|
||||||
|
cb_sector: body.cabinet_sector,
|
||||||
|
dp_id: body.dp_id,
|
||||||
|
userID: body.userID,
|
||||||
|
created_at: new Date(),
|
||||||
|
modified_at: new Date()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create new folder using checked data.
|
||||||
|
const newFolder = await prisma.cabinets.create({ data: folderData })
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: 201,
|
||||||
|
message: "Folder created successfully",
|
||||||
|
folder: newFolder
|
||||||
|
};
|
||||||
|
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user