refactor(services): simplify SQL query strings and reformat function parameters
This commit includes the following changes in `mysql.service.ts` file: - Simplify SQL query strings for `UPDATE` and `INSERT` commands in various methods to make them more readable. - Reformat parameters in `getAllModelsFromCategory` and `delete` methods for better readability. Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
parent
f87aecaf75
commit
fef2bda082
@ -228,9 +228,7 @@ const MySqlService = {
|
||||
actionName: "Update user..",
|
||||
})
|
||||
.then((factorizeResult) => {
|
||||
const _sql = `UPDATE users SET (${factorizeResult._keysTemplate}) WERE id VALUES(${
|
||||
factorizeResult._questionMarksFields
|
||||
})`;
|
||||
const _sql = `UPDATE users SET (${factorizeResult._keysTemplate}) WERE id VALUES(${factorizeResult._questionMarksFields})`;
|
||||
|
||||
try {
|
||||
if (isDebugMode()) handler.Logger.trace(_sql);
|
||||
@ -432,9 +430,7 @@ const MySqlService = {
|
||||
actionName: "Update brand..",
|
||||
})
|
||||
.then((factorizeResult) => {
|
||||
const _sql = `UPDATE brands SET (${factorizeResult._keysTemplate}) WERE id VALUES(${
|
||||
factorizeResult._questionMarksFields
|
||||
})`;
|
||||
const _sql = `UPDATE brands SET (${factorizeResult._keysTemplate}) WERE id VALUES(${factorizeResult._questionMarksFields})`;
|
||||
|
||||
try {
|
||||
if (isDebugMode()) handler.Logger.trace(_sql);
|
||||
@ -672,9 +668,7 @@ const MySqlService = {
|
||||
actionName: "Update model..",
|
||||
})
|
||||
.then((factorizeResult) => {
|
||||
const _sql = `UPDATE models SET (${factorizeResult._keysTemplate}) WERE id VALUES(${
|
||||
factorizeResult._questionMarksFields
|
||||
})`;
|
||||
const _sql = `UPDATE models SET (${factorizeResult._keysTemplate}) WERE id VALUES(${factorizeResult._questionMarksFields})`;
|
||||
|
||||
try {
|
||||
if (isDebugMode()) handler.Logger.trace(_sql);
|
||||
@ -778,9 +772,7 @@ const MySqlService = {
|
||||
actionName: "Update vehicle..",
|
||||
})
|
||||
.then((factorizeResult) => {
|
||||
const _sql = `UPDATE vehicles SET (${factorizeResult._keysTemplate}) WERE id VALUES(${
|
||||
factorizeResult._questionMarksFields
|
||||
})`;
|
||||
const _sql = `UPDATE vehicles SET (${factorizeResult._keysTemplate}) WERE id VALUES(${factorizeResult._questionMarksFields})`;
|
||||
|
||||
try {
|
||||
if (isDebugMode()) handler.Logger.trace(_sql);
|
||||
@ -903,9 +895,9 @@ const MySqlService = {
|
||||
.then((factorizedResult) => {
|
||||
const valuesArray = factorizedResult._valuesArray;
|
||||
const template = factorizedResult._keysTemplate;
|
||||
const _sql = `INSERT INTO categories (${template + `, id`}) VALUES(${
|
||||
factorizedResult._questionMarksFields
|
||||
})`;
|
||||
const _sql = `INSERT INTO categories (${
|
||||
template + `, id`
|
||||
}) VALUES(${factorizedResult._questionMarksFields})`;
|
||||
|
||||
try {
|
||||
if (isDebugMode()) handler.Logger.trace(_sql);
|
||||
@ -939,9 +931,7 @@ const MySqlService = {
|
||||
actionName: "Update brand..",
|
||||
})
|
||||
.then((factorizeResult) => {
|
||||
const _sql = `UPDATE categories SET (${factorizeResult._keysTemplate}) WERE id VALUES(${
|
||||
factorizeResult._questionMarksFields
|
||||
})`;
|
||||
const _sql = `UPDATE categories SET (${factorizeResult._keysTemplate}) WERE id VALUES(${factorizeResult._questionMarksFields})`;
|
||||
|
||||
try {
|
||||
if (isDebugMode()) handler.Logger.trace(_sql);
|
||||
@ -1066,7 +1056,10 @@ const MySqlService = {
|
||||
* @param {string} categoryId - The ID of the category.
|
||||
* @return {Promise<Array<IDbModel>>} - A promise that resolves to an array of database models belonging to the specified category.
|
||||
*/
|
||||
getAllModelsFromCategory(handler: MysqlHandler, categoryId: string): Promise<Array<IDbModel>> {
|
||||
getAllModelsFromCategory(
|
||||
handler: MysqlHandler,
|
||||
categoryId: string,
|
||||
): Promise<Array<IDbModel>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const _sql =
|
||||
"SELECT models.* FROM models INNER JOIN categories ON models.category_id = categories.id WHERE categories.id VALUES(?)";
|
||||
@ -1079,7 +1072,6 @@ const MySqlService = {
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
},
|
||||
Rent: {
|
||||
//ToTest
|
||||
@ -1197,10 +1189,7 @@ const MySqlService = {
|
||||
});
|
||||
},
|
||||
|
||||
delete(
|
||||
handler: MysqlHandler,
|
||||
rentId: string,
|
||||
): Promise<IDbStatusResult> {
|
||||
delete(handler: MysqlHandler, rentId: string): Promise<IDbStatusResult> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!rentId) return reject("Id is undefined");
|
||||
if (rentId.length !== 36) return reject("Id invalid");
|
||||
|
Loading…
x
Reference in New Issue
Block a user