DEV Community

Discussion on: Bulletproof node.js project architecture 🛡️

Collapse
 
santypk4 profile image
Sam

Should not be so different.

A wrapper class needs to be written for every API resource, with a compatible interface across all models.


class UserModel(){

   public UpdateOne(obj: { selector: any, update: any }):Promise<any> {
     // ...API Call
   }

}

Some methods, for example, UpdateMany may not be present in some third-party API resources and so a custom logic needs to be written.


class CompanyModel(){
   public UpdateOne(obj: { selector: any, update: any }):Promise<any> {
     // ...API Call
   }
   public UpdateMany(objs: Array<{ selector: any, update: any }>):Promise<Array<any>> {
     return Promise.all(
           updates.map(u => {
              return this.UpdateOne(u.selector, u.update);
          })
     )
   }

}