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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207import { Hono } from "hono";const router = new Hono();
import { createLicenseType, getLicenseTypes, updatedLicenseType, updatedLicenseTypeStatus,} from "../../services/license";import { license } from "../../config/database/schema";
/** * @route POST /api/v1/license * @desc Add a new license type to the system * @access Public * @params name, description * @return message, data * @error 400, { error } * @status 201, 400 * * @example /api/v1/license **/
router.post("/", async (c) => { const { name, description } = await c.req.json();
if (!name || !description) { return c.json( { message: "Name and description are required", }, 400 ); }
try { let licenseType = await createLicenseType(name, description);
return c.json( { message: "License type created successfully", data: licenseType, }, 201 ); } catch (error) { return c.json( { message: "Internal Server Error", error: error.message, }, 500 ); }});
/** * @route GET /api/v1/license * @desc Get all license types * @access Public * @return message, data * @error 400, { error } * @status 200, 400 * * @example /api/v1/license **/
router.get("/", async (c) => { try { let licenseTypes = await getLicenseTypes();
return c.json( { message: "License types retrieved successfully", data: licenseTypes, }, 200 ); } catch (error) { return c.json( { message: "Internal Server Error", error: error.message, }, 500 ); }});
/** * @route PATCH /api/v1/license/:id * @desc Update an existing license type by ID * @access Public * @params id (path parameter), name, description (request body) * @return message, data * @error 400, { error } * @error 404, { error } * @status 200, 400, 404 * * @example /api/v1/license/:id **/
router.patch("/:id", async (c) => { const licenseId = c.req.param("id"); const { name, description } = await c.req.json();
if (!name || !description) { return c.json( { message: "Name and description are required", }, 400 ); }
try { const updatedLicense = await updatedLicenseType( licenseId, name, description );
if (!updatedLicense) { return c.json( { message: "License type not found", }, 404 ); }
return c.json( { message: "License type updated successfully", data: updatedLicense, }, 200 ); } catch (error) { return c.json( { message: "Internal Server Error", error: error.message, }, 500 ); }});
/** * @route PUT /api/v1/license/update-status * @desc Update an existing license type by ID * @access Public * @params id (path parameter) * @body { "status": "active", "name": "New License Name", "description": "Updated description" } * @return message, data * @error 400, { error } * @error 404, { error } * @status 200, 400, 404 * * @example /api/v1/license/update-status **/
router.put("/update-status", async (c) => { const { status, licenseId } = await c.req.json();
// Validate required fields if (!status && !licenseId) { return c.json( { message: "status, licenseId is required", }, 400 ); }
try { const updatedLicense = await updatedLicenseTypeStatus(status, licenseId);
if (!updatedLicense) { return c.json( { message: "License type not found", }, 404 ); }
return c.json( { message: "License type updated successfully", data: updatedLicense, }, 200 ); } catch (error) { return c.json( { message: "Internal Server Error", error: error.message, }, 500 ); }});export default router;