feat(services): update return types and add documentation in mysql service

The return types for the 'insert' and 'update' methods in mysql.service.ts have been updated to 'Promise<unknown>'. Also, detailed JSDoc comments have been added for 'insert' and 'update' methods for both User and Category entities. No functionality changes have been made.

Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
Mathis H (Avnyr) 2024-04-25 12:11:17 +02:00
parent 47adae9137
commit 2210280edd
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -90,10 +90,10 @@ const MySqlService = {
*
* @param {MysqlHandler} handler - The MySQL database handler.
* @param {IDbUser} data - The user data to insert.
* @returns {Promise<void>} A promise that resolves if the user was inserted successfully, or rejects with an error.
* @returns {Promise<unknown>} A promise that resolves if the user was inserted successfully, or rejects with an error.
* @throws {Error} If an error occurs while executing the query.
*/
insert(handler: MysqlHandler, data: IDbUser) {
insert(handler: MysqlHandler, data: IDbUser): Promise<unknown> {
return new Promise((resolve, reject) => {
if (!data.id) return reject('Id is undefined');
if (data.id.length !== 36) return reject('Id invalid');
@ -112,7 +112,7 @@ const MySqlService = {
data.hash
]
try {
resolve(handler.execute(_sql, _values))
resolve(handler.execute(_sql, _values) as unknown)
} catch (err: unknown) {
reject(err as Error);
}
@ -344,9 +344,15 @@ const MySqlService = {
})
}
},
Category: {
insert(handler: MysqlHandler, data: IDbCategory) {
/**
* Inserts a category into the database.
*
* @param {MysqlHandler} handler - The MySQL handler object.
* @param {IDbCategory} data - The category data to be inserted.
* @return {Promise<unknown>} - A promise that resolves if the insertion is successful, and rejects with an error if it fails.
*/
insert(handler: MysqlHandler, data: IDbCategory): Promise<unknown> {
return new Promise((resolve, reject) => {
if (!data.id) return reject('Id is undefined');
if (data.id.length !== 36) return reject('Id invalid');
@ -365,7 +371,15 @@ const MySqlService = {
})
},
update(handler: MysqlHandler, data: IDbCategory) {
/**
* Updates a category in the database.
*
* @param {MysqlHandler} handler - The MySQL handler instance.
* @param {IDbCategory} data - The category data to update.
* @returns {Promise<unknown>} - A Promise that resolves with the result of the UPDATE query execution.
* @throws {Error} - If an error occurs during execution.
*/
update(handler: MysqlHandler, data: IDbCategory): Promise<unknown> {
return new Promise((resolve, reject) => {
if (!data.id) return reject('Id is undefined');
if (data.id.length !== 36) return reject('Id invalid');
@ -380,7 +394,6 @@ const MySqlService = {
data.display_name,
data.id
]
const _sql = `UPDATE "categories" SET ${_template} WHERE 'id' = ?`;
return resolve(handler.execute(_sql, _values));
@ -388,7 +401,8 @@ const MySqlService = {
reject(err as Error);
}
})
}
},
}
}