-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
existsByEmail 에서 Type '{_id: any; }' is not assignable to type 'boolean'. 에러 발생
22.09.12 15:01 작성 조회수 1.2k
3
@Injectable()
export class CatsRepository {
constructor(@InjectModel(Cat.name) private readonly catModel: Model<Cat>) {}
async existsByEmail(email: string): Promise<boolean> {
try {
const result = await this.catModel.exists({ email });
return result;
} catch (error) {
throw new HttpException('db error', 400);
}
}
}
Type '{_id: any; }' is not assignable to type 'boolean'. 에러가 뜹니다.
여기서 if (result) return result else false 를 하라고 하셨는데, 제가 문법을 잘 모르겠어서 어떻게 써야할 지 모르겠어요... 알려주시면 안될까요? 여기서 막혀서 진도를 못나가요.
답변을 작성해보세요.
6
Young
2022.12.26
async existsByEmail(email: string): Promise<boolean> {
try {
const result = await this.catModel.exists({ email });
if (result) return true;
else return false;
}
catch (error) {
throw new HttpException('db error', 400);
}
}
위와 같이 작성하세요
4
0
bugi
질문자2022.09.12
async existsByEmail(email: string): Promise<boolean> {
try {
const result = await this.catModel.exists({ email });
return !!result;
} catch (error) {
throw new HttpException('db error', 400);
}
}
이렇게 바꿔도 되는건가요?? 예시가 뭔가요?
답변 4