feat(services): add getById function to mysql.service
This commit adds a getById function to the mysql.service.ts file. The added functionality allows retrieving category data from the mysql database by id. Error handling has been included for undefined or invalid id cases. Issue: #6 Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
parent
ead64291df
commit
3328c5a1df
@ -440,7 +440,20 @@ const MySqlService = {
|
|||||||
reject(err as Error);
|
reject(err as Error);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
|
getById(handler: MysqlHandler, categoryId: string): Promise<IDbCategory> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!categoryId) return reject('slug is undefined')
|
||||||
|
if (categoryId.length !== 36) return reject('Id invalid');
|
||||||
|
const _sql = "SELECT * FROM `categories` WHERE `id` = ?";
|
||||||
|
const _values = [categoryId];
|
||||||
|
try {
|
||||||
|
resolve(handler.execute(_sql, _values) as unknown as IDbCategory);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
reject(err as Error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user