Skip to content

Latest commit

 

History

History
46 lines (38 loc) · 1.36 KB

README.md

File metadata and controls

46 lines (38 loc) · 1.36 KB

Discription

Template to handle service for Express, using TypeScript. Making use of SOLID design principles. The code is organized into separate classes and modules, following the single responsibility principle to ensure that each component has a single, well-defined responsibility.

ORM

The example found in the file is using requests with the SQL language, but if you want you can use an ORM, such as Prisma.

    async get(): Promise<Proms[]> {
        try {
            const result = await prisma.base_data.findMany();
            return result;
        } catch (error: any) {
            throw new Error(error.message)
        }
    }
    async post(data: ProducIt): Promise<Proms> {
        try {
            const result = await prisma.base_date.create({ data: data });
            return result;
        } catch (error: any) {
            throw new Error(error.message)
        }
    }

Examples

/* get operation */

    public async  getTask(_req: Request, res: Response) {
        const result = await this.service.get()
        return res.status(200).json(result)
    }
/* post operation */
  public async createTask(req: Request, res: Response) {
         const object: ProducIt = req.body;
         const result = await this.service.post(object)
         return res.status(200).json(result)
    }

Author

Made by Dario Marzzucco (@darmarzz)