Add the update of the title and the content

Colin FRIZOT 11 months ago committed by clfreville2
parent 2e3571b873
commit dd797640d0

@ -361,3 +361,27 @@ export function selectWorkById(db: sqlite3.Database, id: number) {
return getDB(db, selectWorkByIdQuery, [id]);
}
/* Update the work title by its ID */
export function updateWorkTitle(
db: sqlite3.Database,
id: number,
newTitle: string
) {
const updateWorkTitleQuery = `UPDATE work SET title = ? WHERE id_work = ?`;
return runDB(db, updateWorkTitleQuery, [newTitle, id]);
}
/* Update the work content by its ID */
export function updateWorkContent(
db: sqlite3.Database,
id: number,
newContent: string
) {
const updateWorkContentQuery = `UPDATE work SET content = ? WHERE id_work = ?`;
return runDB(db, updateWorkContentQuery, [newContent, id]);
}

@ -536,6 +536,54 @@ fastify.get(
},
);
/* Update the work title by its ID */
fastify.put(
"/works/:id/title",
{
schema: {
params: Type.Object({
id: Type.Number({
minimum: 0,
}),
}),
body: Type.Object({
newTitle: Type.String(),
}),
},
},
async (request, reply) => {
const { id } = request.params;
const { newTitle } = request.body;
db.updateWorkTitle(database, id, newTitle);
reply.send({ success: true });
}
);
/* Update the work content by its ID */
fastify.put(
"/works/:id/content",
{
schema: {
params: Type.Object({
id: Type.Number({
minimum: 0,
}),
}),
body: Type.Object({
newContent: Type.String(),
}),
},
},
async (request, reply) => {
const { id } = request.params;
const { newContent } = request.body;
db.updateWorkContent(database, id, newContent);
reply.send({ success: true });
}
);
/* Forward output est une fonction asynchrone qui permet de récupérer les messages envoyés par le container et de les renvoyer au client */
async function forwardOutput() {
for await (const [buff] of receiver) {

Loading…
Cancel
Save