|
|
@ -4,6 +4,7 @@ import { db } from '$lib/db/db.js';
|
|
|
|
* @typedef {Object} ChangeDBResult
|
|
|
|
* @typedef {Object} ChangeDBResult
|
|
|
|
* @property {string} [error]
|
|
|
|
* @property {string} [error]
|
|
|
|
* @property {string} [success]
|
|
|
|
* @property {string} [success]
|
|
|
|
|
|
|
|
* @property {string} [id]
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -51,29 +52,35 @@ export const delUserFromDB = (email) => {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @function addPosterToDB
|
|
|
|
* @function addPosterToDB
|
|
|
|
* @param {Blob} image
|
|
|
|
* @param {any} image
|
|
|
|
* @param {string} template
|
|
|
|
|
|
|
|
* @param {string} name
|
|
|
|
|
|
|
|
* @param {string} content
|
|
|
|
* @param {string} content
|
|
|
|
* @returns {ChangeDBResult} return
|
|
|
|
* @returns {ChangeDBResult} return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export const addPosterToDB = (image, template, name, content) => {
|
|
|
|
export const addPosterToDB = (image, content) => {
|
|
|
|
|
|
|
|
|
|
|
|
const id = crypto.randomUUID(); // Create random ID for Poster
|
|
|
|
const id = crypto.randomUUID(); // Create random ID for Poster
|
|
|
|
console.log("New id is: ", id);
|
|
|
|
console.log("New id is: ", id);
|
|
|
|
|
|
|
|
|
|
|
|
if (!image || !template || !content) { // Return error if mandatory info is missing
|
|
|
|
const createdAt = Date.now().toString;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!image) { // Return error if mandatory info is missing
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
error: "Image, template or content missing"
|
|
|
|
error: "Image missing"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const addPoster = db.prepare(`INSERT INTO Posters(id,image,template,name,content) VALUES (?,?,?,?,?);`);
|
|
|
|
const addPoster = db.prepare(`INSERT INTO Posters(id,createdAt,image,content) VALUES ($id,$createdAt,$image,$content);`);
|
|
|
|
const result = addPoster.run(id, image, template, name, content);
|
|
|
|
const result = addPoster.run({
|
|
|
|
|
|
|
|
id: id,
|
|
|
|
|
|
|
|
createdAt: createdAt,
|
|
|
|
|
|
|
|
image: image,
|
|
|
|
|
|
|
|
content: content
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (result.changes === 1) {
|
|
|
|
if (result.changes === 1) {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
success: `Poster added to DB with id ${id}`
|
|
|
|
success: `Poster added to DB with id ${id}`,
|
|
|
|
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return { // Default return just in case
|
|
|
|
return { // Default return just in case
|
|
|
|