|
|
|
@ -50,3 +50,34 @@ export const delUserFromDB = (email) => {
|
|
|
|
|
return { error: `Could not remove user '${email}' from DB` }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @function addPosterToDB
|
|
|
|
|
* @param {Blob} image
|
|
|
|
|
* @param {string} template
|
|
|
|
|
* @param {string} name
|
|
|
|
|
* @param {string} content
|
|
|
|
|
* @returns {DBActionResult} return
|
|
|
|
|
*/
|
|
|
|
|
export const addPosterToDB = (image, template, name = "", content) => {
|
|
|
|
|
console.log(`You passed this paramas:\n image: ${image}\n template: ${template}\n name: ${name}\n content: ${content}`);
|
|
|
|
|
|
|
|
|
|
const id = crypto.randomUUID(); // Create random ID for Poster
|
|
|
|
|
|
|
|
|
|
if (!image || !template || !content) { // Return error if mandatory info is missing
|
|
|
|
|
return {
|
|
|
|
|
error: "Image, template or content missing"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const addPoster = db.prepare(`INSERT INTO Posters(id,image,template,name,content) VALUES (?,?,?,?,?);`);
|
|
|
|
|
const result = addPoster.run(id, image, template, name, content);
|
|
|
|
|
|
|
|
|
|
if (result.changes === 1) {
|
|
|
|
|
return {
|
|
|
|
|
success: `Poster added to DB with id ${id}`
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return { // Default return just in case
|
|
|
|
|
error: `Could not save poster '${id}' to DB. Something went wrong`
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|