import { provide } from 'inversify-binding-decorators' ; import TYPES from '../constant/types' ; import { MongoDBClient } from '../utils/mongodb/client' ; import { User } from '../models/user' ; import { inject } from 'inversify' ; @ provide ( TYPES . UserService ) export class UserService { private mongoClient : MongoDBClient ; constructor ( @ inject ( TYPES . MongoDBClient ) mongoClient ) { this . mongoClient = mongoClient ; } public getUsers ( ) { return new Promise < User [ ] > ( ( resolve , reject ) => { this . mongoClient . find ( 'user' , { } , ( error , data ) => { resolve ( data ) ; } ) ; } ) ; } public getUser ( id ) { return new Promise < User > ( ( resolve , reject ) => { this . mongoClient . findOneById ( 'user' , id , ( error , data ) => { resolve ( data ) ; } ) ; } ) ; } public newUser ( user ) { return new Promise < User > ( ( resolve , reject ) => { this . mongoClient . insert ( 'user' , user , ( error , data ) => { resolve ( data ) ; } ) ; } ) ; } public updateUser ( id , user ) { return new Promise < User > ( ( resolve , reject ) => { this . mongoClient . update ( 'user' , id , user , ( error , data ) => { resolve ( data ) ; } ) ; } ) ; } public deleteUser ( id ) { return new Promise < any > ( ( resolve , reject ) => { this . mongoClient . remove ( 'user' , id , ( error , data ) => { resolve ( data ) ; } ) ; } ) ; } }