Something went wrong. Try again.
A comprehensive digital solution dedicated to bridging the gap between those offering services and those seeking them, providing a centrali… gigwork.co.in
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192import { count, eq, sql } from "drizzle-orm";import { db } from "../config/database/turso";
import { licenseType } from "../config/database/schema";
// Create a new license typeexport const createLicenseType = async (name: string, description: string) => { return new Promise(async (resolve, reject) => { try { // SQL Query : INSERT INTO license_type (name, description) VALUES (name, description)
let result = await db .insert(licenseType) .values({ name, description }) .returning(); result = result[0];
return resolve(result); } catch (error) { reject(error); } });};
// Get all license typesexport const getLicenseTypes = async () => { return new Promise(async (resolve, reject) => { try { // SQL Query : SELECT * FROM license_type
let result = await db .select({ id: licenseType.id, name: licenseType.name, description: licenseType.description, status: sql`CASE WHEN ${licenseType.status} = 1 THEN true ELSE false END`.mapWith( Boolean ), }) .from(licenseType); return resolve(result); } catch (error) { reject(error); } });};
// Update a licenseexport const updatedLicenseType = async ( id: string, name: string, description: string) => { return new Promise(async (resolve, reject) => { try { // SQL Query: UPDATE license_type SET name = name, description = description WHERE id = id
const updatedLicenseType = await db .update(licenseType) .set({ name, description }) .where(eq(licenseType.id, id)) .returning();
resolve(updatedLicenseType[0]); } catch (error) { reject(error); } });};
export const updatedLicenseTypeStatus = async ( status: number, licenseId: string) => { return new Promise(async (resolve, reject) => { try { // SQL Query: UPDATE license_type SET status = status WHERE id = id
const updatedLicenseType = await db .update(licenseType) .set({ status, updated_at: sql`(CURRENT_TIMESTAMP)` }) .where(eq(licenseType.id, licenseId)) .returning();
resolve(updatedLicenseType[0]); } catch (error) { reject(error); } });};