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..",
|
actionName: "Update user..",
|
||||||
})
|
})
|
||||||
.then((factorizeResult) => {
|
.then((factorizeResult) => {
|
||||||
const _sql = `UPDATE users SET (${factorizeResult._keysTemplate}) WERE id VALUES(${
|
const _sql = `UPDATE users SET (${factorizeResult._keysTemplate}) WERE id VALUES(${factorizeResult._questionMarksFields})`;
|
||||||
factorizeResult._questionMarksFields
|
|
||||||
})`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isDebugMode()) handler.Logger.trace(_sql);
|
if (isDebugMode()) handler.Logger.trace(_sql);
|
||||||
@ -432,9 +430,7 @@ const MySqlService = {
|
|||||||
actionName: "Update brand..",
|
actionName: "Update brand..",
|
||||||
})
|
})
|
||||||
.then((factorizeResult) => {
|
.then((factorizeResult) => {
|
||||||
const _sql = `UPDATE brands SET (${factorizeResult._keysTemplate}) WERE id VALUES(${
|
const _sql = `UPDATE brands SET (${factorizeResult._keysTemplate}) WERE id VALUES(${factorizeResult._questionMarksFields})`;
|
||||||
factorizeResult._questionMarksFields
|
|
||||||
})`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isDebugMode()) handler.Logger.trace(_sql);
|
if (isDebugMode()) handler.Logger.trace(_sql);
|
||||||
@ -672,9 +668,7 @@ const MySqlService = {
|
|||||||
actionName: "Update model..",
|
actionName: "Update model..",
|
||||||
})
|
})
|
||||||
.then((factorizeResult) => {
|
.then((factorizeResult) => {
|
||||||
const _sql = `UPDATE models SET (${factorizeResult._keysTemplate}) WERE id VALUES(${
|
const _sql = `UPDATE models SET (${factorizeResult._keysTemplate}) WERE id VALUES(${factorizeResult._questionMarksFields})`;
|
||||||
factorizeResult._questionMarksFields
|
|
||||||
})`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isDebugMode()) handler.Logger.trace(_sql);
|
if (isDebugMode()) handler.Logger.trace(_sql);
|
||||||
@ -778,9 +772,7 @@ const MySqlService = {
|
|||||||
actionName: "Update vehicle..",
|
actionName: "Update vehicle..",
|
||||||
})
|
})
|
||||||
.then((factorizeResult) => {
|
.then((factorizeResult) => {
|
||||||
const _sql = `UPDATE vehicles SET (${factorizeResult._keysTemplate}) WERE id VALUES(${
|
const _sql = `UPDATE vehicles SET (${factorizeResult._keysTemplate}) WERE id VALUES(${factorizeResult._questionMarksFields})`;
|
||||||
factorizeResult._questionMarksFields
|
|
||||||
})`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isDebugMode()) handler.Logger.trace(_sql);
|
if (isDebugMode()) handler.Logger.trace(_sql);
|
||||||
@ -903,9 +895,9 @@ const MySqlService = {
|
|||||||
.then((factorizedResult) => {
|
.then((factorizedResult) => {
|
||||||
const valuesArray = factorizedResult._valuesArray;
|
const valuesArray = factorizedResult._valuesArray;
|
||||||
const template = factorizedResult._keysTemplate;
|
const template = factorizedResult._keysTemplate;
|
||||||
const _sql = `INSERT INTO categories (${template + `, id`}) VALUES(${
|
const _sql = `INSERT INTO categories (${
|
||||||
factorizedResult._questionMarksFields
|
template + `, id`
|
||||||
})`;
|
}) VALUES(${factorizedResult._questionMarksFields})`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isDebugMode()) handler.Logger.trace(_sql);
|
if (isDebugMode()) handler.Logger.trace(_sql);
|
||||||
@ -939,9 +931,7 @@ const MySqlService = {
|
|||||||
actionName: "Update brand..",
|
actionName: "Update brand..",
|
||||||
})
|
})
|
||||||
.then((factorizeResult) => {
|
.then((factorizeResult) => {
|
||||||
const _sql = `UPDATE categories SET (${factorizeResult._keysTemplate}) WERE id VALUES(${
|
const _sql = `UPDATE categories SET (${factorizeResult._keysTemplate}) WERE id VALUES(${factorizeResult._questionMarksFields})`;
|
||||||
factorizeResult._questionMarksFields
|
|
||||||
})`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isDebugMode()) handler.Logger.trace(_sql);
|
if (isDebugMode()) handler.Logger.trace(_sql);
|
||||||
@ -1066,7 +1056,10 @@ const MySqlService = {
|
|||||||
* @param {string} categoryId - The ID of the category.
|
* @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.
|
* @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) => {
|
return new Promise((resolve, reject) => {
|
||||||
const _sql =
|
const _sql =
|
||||||
"SELECT models.* FROM models INNER JOIN categories ON models.category_id = categories.id WHERE categories.id VALUES(?)";
|
"SELECT models.* FROM models INNER JOIN categories ON models.category_id = categories.id WHERE categories.id VALUES(?)";
|
||||||
@ -1079,7 +1072,6 @@ const MySqlService = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
Rent: {
|
Rent: {
|
||||||
//ToTest
|
//ToTest
|
||||||
@ -1197,10 +1189,7 @@ const MySqlService = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
delete(
|
delete(handler: MysqlHandler, rentId: string): Promise<IDbStatusResult> {
|
||||||
handler: MysqlHandler,
|
|
||||||
rentId: string,
|
|
||||||
): Promise<IDbStatusResult> {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!rentId) return reject("Id is undefined");
|
if (!rentId) return reject("Id is undefined");
|
||||||
if (rentId.length !== 36) return reject("Id invalid");
|
if (rentId.length !== 36) return reject("Id invalid");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user