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:
parent
47adae9137
commit
2210280edd
@ -90,10 +90,10 @@ const MySqlService = {
|
|||||||
*
|
*
|
||||||
* @param {MysqlHandler} handler - The MySQL database handler.
|
* @param {MysqlHandler} handler - The MySQL database handler.
|
||||||
* @param {IDbUser} data - The user data to insert.
|
* @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.
|
* @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) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!data.id) return reject('Id is undefined');
|
if (!data.id) return reject('Id is undefined');
|
||||||
if (data.id.length !== 36) return reject('Id invalid');
|
if (data.id.length !== 36) return reject('Id invalid');
|
||||||
@ -112,7 +112,7 @@ const MySqlService = {
|
|||||||
data.hash
|
data.hash
|
||||||
]
|
]
|
||||||
try {
|
try {
|
||||||
resolve(handler.execute(_sql, _values))
|
resolve(handler.execute(_sql, _values) as unknown)
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
reject(err as Error);
|
reject(err as Error);
|
||||||
}
|
}
|
||||||
@ -344,9 +344,15 @@ const MySqlService = {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Category: {
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!data.id) return reject('Id is undefined');
|
if (!data.id) return reject('Id is undefined');
|
||||||
if (data.id.length !== 36) return reject('Id invalid');
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!data.id) return reject('Id is undefined');
|
if (!data.id) return reject('Id is undefined');
|
||||||
if (data.id.length !== 36) return reject('Id invalid');
|
if (data.id.length !== 36) return reject('Id invalid');
|
||||||
@ -380,7 +394,6 @@ const MySqlService = {
|
|||||||
data.display_name,
|
data.display_name,
|
||||||
data.id
|
data.id
|
||||||
]
|
]
|
||||||
|
|
||||||
const _sql = `UPDATE "categories" SET ${_template} WHERE 'id' = ?`;
|
const _sql = `UPDATE "categories" SET ${_template} WHERE 'id' = ?`;
|
||||||
return resolve(handler.execute(_sql, _values));
|
return resolve(handler.execute(_sql, _values));
|
||||||
|
|
||||||
@ -388,7 +401,8 @@ const MySqlService = {
|
|||||||
reject(err as Error);
|
reject(err as Error);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user