Add the update of the title and the content
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

Colin FRIZOT 11 months ago
parent a9651ed09f
commit 9c194b218d

@ -353,3 +353,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]);
}

@ -488,6 +488,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