Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 68 additions & 88 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export class UserController {
return this.userService.findOne(+id);
}

@Get('/findbypassword/:password')
find(@Param('password') password: string) {
console.log(password);
return this.userService.find(password);
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
return this.userService.update(+id, updateUserDto);
Expand Down
18 changes: 15 additions & 3 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Injectable } from '@nestjs/common';
import { Injectable, NotFoundException } from '@nestjs/common';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from './entities/user.entity';
import { Repository } from 'typeorm';
import { ILike, Repository } from 'typeorm';

@Injectable()
export class UserService {
Expand All @@ -16,7 +16,19 @@ export class UserService {
}

findAll() {
return this.usersRepository.find({});
return this.usersRepository.find({
select: ['id', 'username'], //SELECT id, username FROM user
where: { username: 'admin' }, //WHERE username = 'admin'
});
}

async find(password: string) {
const [data, count] = await this.usersRepository.findAndCount({
where: { userPassword: ILike('%' + password + '%') },
});
if (count === 0) throw new NotFoundException();

return data;
}

findOne(id: number) {
Expand Down