Files
HRM/src/routes/api/employees/[id]/+server.ts
T

25 lines
1.0 KiB
TypeScript

import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import type { EmployeeRecord } from '../+server';
const COLLECTION = 'Employee_Records';
export const PATCH: RequestHandler = async ({ params, request, locals }) => {
const id = params.id;
const body = await request.json();
const record = await locals.pb.collection(COLLECTION).update<EmployeeRecord>(id, {
...(body.First_Name !== undefined && { First_Name: body.First_Name }),
...(body.Last_Name !== undefined && { Last_Name: body.Last_Name }),
...(body.Phone_Number !== undefined && { Phone_Number: body.Phone_Number }),
...(body.Email_Address !== undefined && { Email_Address: body.Email_Address }),
...(body.Voxer_ID !== undefined && { Voxer_ID: body.Voxer_ID }),
...(body.Status !== undefined && { Status: body.Status })
});
return json(record);
};
export const DELETE: RequestHandler = async ({ params, locals }) => {
await locals.pb.collection(COLLECTION).delete(params.id);
return new Response(null, { status: 204 });
};