add: schedule db
This commit is contained in:
@@ -14,7 +14,11 @@ const getAllRolesDb = async (searchParams = {}) => {
|
||||
const { whereConditions, whereParamAnd } = pool.buildFilterQuery(
|
||||
[
|
||||
{ column: "r.role_name", param: searchParams.role_name, type: "string" },
|
||||
{ column: "r.role_level", param: searchParams.role_level, type: "number" },
|
||||
{
|
||||
column: "r.role_level",
|
||||
param: searchParams.role_level,
|
||||
type: "number",
|
||||
},
|
||||
],
|
||||
queryParams
|
||||
);
|
||||
@@ -38,14 +42,15 @@ const getAllRolesDb = async (searchParams = {}) => {
|
||||
WHERE r.deleted_at IS NULL
|
||||
${whereConditions.length > 0 ? `AND ${whereConditions.join(" AND ")}` : ""}
|
||||
ORDER BY r.role_id ASC
|
||||
${searchParams.limit ? `OFFSET $2 ROWS FETCH NEXT $1 ROWS ONLY` : ''};
|
||||
${searchParams.limit ? `OFFSET $2 ROWS FETCH NEXT $1 ROWS ONLY` : ""};
|
||||
`;
|
||||
|
||||
const result = await pool.query(queryText, queryParams);
|
||||
|
||||
const total = result?.recordset.length > 0
|
||||
? parseInt(result.recordset[0].total_data, 10)
|
||||
: 0;
|
||||
const total =
|
||||
result?.recordset.length > 0
|
||||
? parseInt(result.recordset[0].total_data, 10)
|
||||
: 0;
|
||||
|
||||
return { data: result.recordset, total };
|
||||
};
|
||||
@@ -75,7 +80,10 @@ const getRolesByIdDb = async (id) => {
|
||||
const createRolesDB = async (data) => {
|
||||
const store = { ...data };
|
||||
|
||||
const { query: queryText, values } = pool.buildDynamicInsert("m_roles", store);
|
||||
const { query: queryText, values } = pool.buildDynamicInsert(
|
||||
"m_roles",
|
||||
store
|
||||
);
|
||||
const result = await pool.query(queryText, values);
|
||||
|
||||
const insertedId = result.recordset[0]?.inserted_id;
|
||||
@@ -87,7 +95,11 @@ const updateRolesDb = async (id, data) => {
|
||||
const store = { ...data };
|
||||
const whereData = { role_id: id };
|
||||
|
||||
const { query: queryText, values } = pool.buildDynamicUpdate("m_roles", store, whereData);
|
||||
const { query: queryText, values } = pool.buildDynamicUpdate(
|
||||
"m_roles",
|
||||
store,
|
||||
whereData
|
||||
);
|
||||
await pool.query(`${queryText} AND deleted_at IS NULL`, values);
|
||||
|
||||
return getRolesByIdDb(id);
|
||||
|
||||
Reference in New Issue
Block a user