add : CRUD roles

This commit is contained in:
Muhammad Afif
2025-10-09 13:22:41 +07:00
parent 5d27056906
commit c81e8ef22d
4 changed files with 195 additions and 3 deletions

View File

@@ -51,19 +51,23 @@ const getRoleByIdDb = async (id) => {
// Create role
const createRoleDb = async (data) => {
const roles = { ...data };
const { query, values } = pool.buildDynamicInsert("m_roles", {
...data,
created_at: new Date(),
...roles,
});
const result = await pool.query(query, values);
return result.recordset[0]?.inserted_id || null;
};
// Update role
const updateRoleDb = async (id, data) => {
const { query, values } = pool.buildDynamicUpdate(
"m_roles",
{ ...data, updated_at: new Date() },
{ ...data },
{ role_id: id }
);
await pool.query(query, values);