2024. 8. 2. 14:06ใTIL
๐กํ๋ก์ ํธ ์งํ์ค ํธ๋ฌ๋ธ์ํ
* ์ํฉ
- ์ค์ผ์ค ๊ด๋ฆฌ ์ฝ๋ ์์ฑ์ค substoryhistory ํ ์ด๋ธ์ ๋ด๊ธด nextPayAt ๋ ์ง ํ๋ฃจ ์ ๋ ์๋์ ๋ณด๋ด์ฃผ๊ธฐ ์ํด
์๋์ผ์ ์ค์ ํ๋์ค nextPayAt ๋ ์ง์ tomorrow ๋ณ์๊ฐ ์ผ์นํ ํ๋๋ก ์ฝ๋๋ฅผ ์์ฑํ๋ ๋ฐ
1. ๋ฌธ์
๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ด์ผ์ด ๊ฒฐ์ ์ผ์ธ ๋ฐ์ดํฐ๊ฐ ์๋ ๋ฐ ' ๋ด์ผ์ธ ๊ฒฐ์ ์ด๋ ฅ '์ด ๋น ๋ฐฐ์ด๋ก ๋์ค๋ ์ํฉ ํ์ธ.
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
// nextPayAt: ๊ฒฐ์ ๋ ์ง
const subscriptionHistories =
await this.subscriptionHistoriesRepository.find({
where: {
nextPayAt: tomorrow,
},
relations: [
'userSubscription',
'userSubscription.user',
'userSubscription.platform',
],
});
console.log('๋ด์ผ์ธ ๊ฒฐ์ ์ด๋ ฅ', subscriptionHistories);
2. ํด๊ฒฐ๋ฐฉ์
- ๊ด๋ จ ๋ด์ฉ์ ๊ฒ์ํด๋ณธ ๊ฒฐ๊ณผ new Date()๋ก ๋ ์ง๋ฅผ ์ง์ ํด์ค ๊ฒฝ์ฐ ํ์ฌ์๊ฐ์ด ํจ๊ป ์ ์ฅ๋์ด ex) 2024-08-02 12:50:00
๋ค์๊ฒฐ์ ์ผ์ธ 2024-08-02 00:00:00 ๊ณผ ์ผ์นํ์ง ์์ ๊ฒ์ ์๊ฒ ๋์์ต๋๋ค.
- setHours(0, 0, 0, 0); ์ ์ฌ์ฉํ์ฌ tomorrow์๊ฐ์ 00:00:00 ๋ก ์ค์ ํ์ฌ ๋ ์ง๋ง ๋น๊ตํ์ฌ ๊ฐ์ ธ์ฌ ์ ์๋๋ก ์์ ํด์ฃผ์์ต๋๋ค.
- ์ฝ๋ ์คํ๊ฒฐ๊ณผ ๋ด์ผ์ธ ๊ฒฐ์ ์ด๋ ฅ์ ์ ๋ถ๋ฌ ์์ง๋ ๊ฒ์ ํ์ธ ํ ์ ์์์ต๋๋ค.
const tomorrow = new Date();
tomorrow.setHours(0, 0, 0, 0); //์๊ฐ์ค์ ์ถ๊ฐ
tomorrow.setDate(tomorrow.getDate() + 1);
const subscriptionHistories =
await this.subscriptionHistoriesRepository.find({
where: {
nextPayAt: tomorrow,
},
relations: [
'userSubscription',
'userSubscription.user',
'userSubscription.platform',
],
});
console.log('๋ด์ผ์ธ ๊ฒฐ์ ์ด๋ ฅ', subscriptionHistories);
'TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
TIL ( fk์ index) (0) | 2024.08.06 |
---|---|
TIL (์ด์ค ๋ฐฐ์ด๊ฐ ๋ฐํํ๊ธฐ) (0) | 2024.08.05 |
TIL ( ์คํ๊ณผ ํ ) (0) | 2024.08.01 |
TIL ( 3์ฐจ ๋ชจ์๋ฉด์ ) (0) | 2024.07.31 |
TIL ( nodejs๋ ์ฑ๊ธ์ค๋ ๋์ธ๊ฐ์ ๋ํ์ฌ ) (0) | 2024.07.30 |