☀️ BE TIL Day 17 0405
⬇️ Main Note
https://docs.google.com/document/d/1jg42VWIjpds0XRxHElcLG8Fz64XJpbgBc3-rnTXGdI4/edit
isSoldout is in a boolean type, which the default value is written as false. When isSoldout changes into true, then the user cannot edit the product.
https://docs.google.com/document/d/1jg42VWIjpds0XRxHElcLG8Fz64XJpbgBc3-rnTXGdI4/edit
🌼 Building CRUD API
🌿 Type settings
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;
}
🌿 Entity Query Settings
🌼 Try-Catch
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 shortcutcommand + shift + L
=> select all the identical wordsReference
この問題について(☀️ BE TIL Day 17 0405), 我々は、より多くの情報をここで見つけました https://velog.io/@j00b33/BE-TIL-Day-17-0405テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol