Files
worklenz/worklenz-backend/src/socket.io/commands/on-task-billable-change.ts
chamikaJ 8825b0410a init
2025-04-17 18:28:54 +05:30

21 lines
691 B
TypeScript

import { Server, Socket } from "socket.io";
import { log_error } from "../util";
import db from "../../config/db";
import { SocketEvents } from "../events";
import { body } from "express-validator";
export async function on_task_billable_change(_io: Server, socket: Socket, data?: {task_id?: string, billable?: boolean}) {
if (!data?.task_id || (typeof data.billable != "boolean")) return;
try {
const q = `UPDATE tasks SET billable = $2 WHERE id = $1`;
await db.query(q, [data?.task_id, data?.billable]);
socket.emit(SocketEvents.TASK_BILLABLE_CHANGE.toString(), {
id: data?.task_id
});
} catch (e) {
log_error(e);
}
}