⬇️ Main Note
https://docs.google.com/document/d/1jg42VWIjpds0XRxHElcLG8Fz64XJpbgBc3-rnTXGdI4/edit
export class Product {
@PrimaryGeneratedColumn('uuid')
@Field(() => String)
id: string;
@Column()
@Field(() => String)
name: string;
@Column()
@Field(() => Int)
price: number;
@Column({ default: false }) // mysql에 들어가는 부분
@Field(() => Boolean)
isSoldout: boolean;
}
async checkSoldout({ productId }) { // checking with the productId that was sent from resolver
try {
const product = await this.productRepository.findOne({
where: { id: productId },
});
console.log('logic check');
} catch (error) {
throw error.message;
} finally {
// logic here is anyway executed whatever there is an error or not
}
if (product.isSoldout) // ===if (product.isSoldout === true)
throw new UnprocessableEntityException('이미 판매 완료된 상품입니다');
// ===> condensed version of...
// if (product.isSoldout) {
// throw new HttpException(
// '이미 판매가 완료된 상품입니다',
// HttpStatus.UNPROCESSABLE_ENTITY, // 422 error
// );
// }
}
⬇️ command shortcut
command + shift + L
=> select all the identical words