Skip to content

Template to handle service operations 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.

Notifications You must be signed in to change notification settings

DMarzzucco/UserServiceHandler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

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)

About

Template to handle service operations 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.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published