import { Where, repository } from '@loopback/repository'; import { post, param, get, patch, del, requestBody } from '@loopback/rest'; import { User } from '../models'; import { UserlRepository } from '../repositories'; export class UserlController { constructor(@repository(UserlRepository) public userlRepository: UserlRepository) {} @post('/usersl/signup') async create(@requestBody() obj: User): Promise { let userget = await this.find(); let count = 0; userget.map(user => { if (user.email === obj.email) count++; }); let confermation = { statusmessage: '', statuscode: '', }; if (count === 0) { await this.userlRepository.create(obj); return (confermation = { statusmessage: 'succefully user created', statuscode: '200', }); } return (confermation = { statusmessage: 'failed user created', statuscode: '400', }); } @post('/usersl/login') async login(@requestBody() obj: User): Promise { let userget = await this.find(); let count = 0; let email = ''; let password = ''; userget.map(user => { if (user.email === obj.email) { email = user.email; password = user.password; count++; } }); let confermation = { statusmessage: '', statuscode: '', }; if (count > 0) { if (email === obj.email && password === obj.password) return (confermation = { statusmessage: 'succefully user loged in', statuscode: '200', }); return (confermation = { statusmessage: 'invalid loged credentials', statuscode: '400', }); } return (confermation = { statusmessage: 'failed user not exist', statuscode: '400', }); } @get('/usersl/count') async count(@param.query.string('where') where?: Where): Promise { return await this.userlRepository.count(where); } @get('/usersl') async find(): Promise { return await this.userlRepository.find(); } @patch('/usersl') async updateAll(@requestBody() obj: User, @param.query.string('where') where?: Where): Promise { return await this.userlRepository.updateAll(obj, where); } @get('/usersl/{id}') async findById(@param.path.string('id') id: string): Promise { return await this.userlRepository.findById(id); } @patch('/usersl/{id}') async updateById(@param.path.string('id') id: string, @requestBody() obj: User): Promise { return await this.userlRepository.updateById(id, obj); } @del('/usersl/{id}') async deleteById(@param.path.string('id') id: string): Promise { return await this.userlRepository.deleteById(id); } }