Mostly Front End & UI fixes

This commit is contained in:
2024-07-20 09:12:29 -05:00
parent 8e02288d3d
commit 5f020bf542
12 changed files with 176 additions and 151 deletions

View File

@ -15,7 +15,7 @@ export const users = createTable(
id: bigint("id", {mode: "number"}).primaryKey().autoincrement(),
name: varchar("name", { length: 256 }).notNull(),
status: varchar("status", { length: 256 }).notNull(),
updatedAt: timestamp("updated_at")
updatedAt: timestamp("updatedAt")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
},
@ -27,6 +27,6 @@ export const history = createTable(
id: bigint("id", {mode: "number"}).primaryKey().autoincrement(),
user_id: bigint("user_id", {mode: "number"}).references(() => users.id),
status: varchar("status", { length: 256 }).notNull(),
updatedAt: timestamp("updated_at").notNull(),
updatedAt: timestamp("updatedAt").notNull(),
},
);

View File

@ -10,20 +10,21 @@ export const getEmployees = async () => {
};
// Function to Update Employee Status using Raw SQL
export const updateEmployeeStatus = async (employeeIds: number[], newStatus: string) => {
export const updateEmployeeStatus = async (employeeIds: string[], newStatus: string) => {
try {
// Convert array of ids to a format suitable for SQL query (comma-separated string)
const idString = employeeIds.join(",");
const idList = employeeIds.map(id => parseInt(id, 10));
const updatedAt = new Date();
// Prepare the raw SQL query with embedded variables
const query = `
// Prepare the query using drizzle-orm's template-like syntax for escaping variables
const query = sql`
UPDATE users
SET status = '${newStatus}', updatedAt = '${new Date().toISOString()}'
WHERE id IN (${idString})
SET status = ${newStatus}, updatedAt = ${updatedAt}
WHERE id IN ${idList}
`;
// Execute the raw SQL query using the execute method
await db.execute(sql`${query}`);
// Execute the query
await db.execute(query);
return { success: true };
} catch (error) {