diff --git a/src/config/index.ts b/src/config/index.ts index 3bf48c8fc881bf8611016389c8321c7cfef1f121..59e24a6e8571858d6183cc6dfe3b3b093ad368dc 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,4 +1,4 @@ -import * as _config from './config.json'; +import * as _config from './config.template.json'; import { IConfig } from './config.model'; const config = _config as IConfig; diff --git a/src/people/dao/people.dao.ts b/src/people/dao/people.dao.ts index 39dc137ba81a5cdcdacf215cbe1a9c38ba04313d..61f707a6c3c945f467e674b20e255bb3d1967009 100644 --- a/src/people/dao/people.dao.ts +++ b/src/people/dao/people.dao.ts @@ -17,6 +17,15 @@ export class PeopleDao { private readonly _peopleModel: Model<People>, ) {} + login = (email: string, password: string): Promise<People | void> => + new Promise((resolve, reject) => { + this._peopleModel.findOne({email : email, passwordHash : password}, (err, value) => { + if (err) reject(err.message); + if (!value) reject(new NotFoundException('Email or password is incorrect!')); + resolve(value); + }); + }); + find = (): Promise<People[]> => new Promise((resolve, reject) => { this._peopleModel.find({}, {}, {}, (err, value) => { diff --git a/src/people/people.controller.ts b/src/people/people.controller.ts index 8d40c28a36275093db88ba1b57c7a03ca670e677..4b382b4aba84cb4f27e6531200d28515ab9bd054 100644 --- a/src/people/people.controller.ts +++ b/src/people/people.controller.ts @@ -16,11 +16,21 @@ import { HttpInterceptor } from '../interceptors/http.interceptor'; import { PeopleEntity } from './entities/people.entity'; import { PeopleService } from './people.service'; + interface Login { + email: string; + password: string; +} + @Controller('people') @UseInterceptors(HttpInterceptor) export class PeopleController { constructor(private readonly _peopleService: PeopleService) {} + @Post('/login') + login(@Body() login: Login): Promise<PeopleEntity | void> { + return this._peopleService.login(login.email, login.password); + } + @Get() findAll(): Promise<PeopleEntity[] | void> { return this._peopleService.findAll(); diff --git a/src/people/people.service.ts b/src/people/people.service.ts index e97344a5d049104065cd802bd97b5ba6e7bb5b4b..5ea05b6f47a55bde346071bc7ec1c5ffd67fd223 100644 --- a/src/people/people.service.ts +++ b/src/people/people.service.ts @@ -8,6 +8,9 @@ import { PeopleEntity } from './entities/people.entity'; export class PeopleService { constructor(private readonly _peopleDao: PeopleDao) {} + login = (email: string, password: string): Promise<PeopleEntity | void> => + this._peopleDao.login(email, password); + findAll = (): Promise<PeopleEntity[] | void> => this._peopleDao.find(); findOne = (id: string): Promise<PeopleEntity | void> =>