import "reflect-metadata";
import { Controller, Patch, Route, Body } from "@tsoa/runtime";
import coreService from "~/services/core";

interface LockRequest {
	table: string;
	col: string;
	value: any;
	key: string;
	id: string | number;
}

@Route("lock")
export class LockController extends Controller {
	/**
	 * Partially updates lock data
	 */
	@Patch()
	public async patch(@Body() body: LockRequest): Promise<any> {
		return await coreService.patch({
			table: body.table,
			patchBody: [
				{
					type: "int",
					col: body.col,
					value: body.value,
				},
			],
			whereClause: `${body.key}=${body.id}`,
		});
	}
}
