-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
509324e
commit 0f5977a
Showing
9 changed files
with
428 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
const InventoryService = require("../utils/inventory") | ||
const InventoryService = require("../utils/inventory"); | ||
|
||
const startDate = "2023-11-01" | ||
const endDate = "2023-11-12" | ||
|
||
|
||
|
||
it('1', async () => { | ||
const test = await InventoryService.calculateInventory(endDate); | ||
|
||
console.log(JSON.stringify(test, null, 2)) | ||
const startDate = "2023-11-01"; | ||
const endDate = "2023-11-14"; | ||
// 엑셀생성 자료 테스트 | ||
it("1", async () => { | ||
// await InventoryService.createSnapshotForItem(115, 11); | ||
// await InventoryService.createSnapshotForItem(407, 15); | ||
const test = await InventoryService.getCombinedChanges(startDate, endDate); | ||
console.log(test); | ||
}); | ||
|
||
|
||
|
||
// it("2", async () => { | ||
// const test = await InventoryService.getReceiptChanges(startDate, endDate); | ||
// console.log(test); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const InventoryService = require("@inventory"); | ||
|
||
router.get("/", async (req, res) => { | ||
try { | ||
const inventoryChanges = await InventoryService.getItemList(); | ||
|
||
if (inventoryChanges.length > 0) { | ||
res.status(200).send(inventoryChanges); | ||
} else { | ||
res.status(204).json({ message: "아이템 목록이 없습니다." }); | ||
} | ||
} catch (err) { | ||
console.error("Error", err); | ||
res.status(500).json({ error: "Internal server error." }); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const InventoryService = require("@inventory"); | ||
|
||
router.get("/", async (req, res) => { | ||
const { start_date, end_date } = req.query; | ||
|
||
try { | ||
// 재고 변동사항을 조회합니다. | ||
const inventoryChanges = await InventoryService.getReceiptChanges( | ||
start_date, | ||
end_date, | ||
); | ||
|
||
if (inventoryChanges.length > 0) { | ||
res.status(200).send(inventoryChanges); | ||
} else { | ||
res | ||
.status(204) | ||
.json({ message: "해당 기간에 재고가 존재하지 않습니다." }); | ||
} | ||
} catch (err) { | ||
console.error("Error", err); | ||
res.status(500).json({ error: "Internal server error." }); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const InventoryService = require("@inventory"); | ||
|
||
router.get("/", async (req, res) => { | ||
const { start_date, end_date } = req.query; | ||
|
||
try { | ||
// 재고 변동사항을 조회합니다. | ||
const inventoryChanges = await InventoryService.getCombinedChanges( | ||
start_date, | ||
end_date, | ||
); | ||
|
||
if (inventoryChanges.length > 0) { | ||
res.status(200).send(inventoryChanges); | ||
} else { | ||
res | ||
.status(204) | ||
.json({ message: "해당 기간에 재고가 존재하지 않습니다." }); | ||
} | ||
} catch (err) { | ||
console.error("Error", err); | ||
res.status(500).json({ error: "Internal server error." }); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
const moment = require('moment-timezone'); | ||
const moment = require("moment-timezone"); | ||
|
||
function convertKSTtoUTC(kstDate) { | ||
// KST 날짜 문자열을 받아서 UTC로 변환한 Moment 객체를 반환합니다. | ||
return moment.tz(kstDate, 'Asia/Seoul').utc().format(); | ||
return moment.tz(kstDate, "Asia/Seoul").utc().format(); | ||
} | ||
|
||
function addEndTimeAndConvertToUTC(kstDate) { | ||
// KST 기준으로 하루의 끝에 해당하는 시간을 설정합니다. | ||
const kstEndDate = moment.tz(kstDate, 'Asia/Seoul').endOf('day'); | ||
const kstEndDate = moment.tz(kstDate, "Asia/Seoul").endOf("day"); | ||
// 그리고 UTC로 변환합니다. | ||
return kstEndDate.utc().format(); | ||
} | ||
|
||
function subtractOneDayAndConvertToUTC(kstDate) { | ||
// KST 날짜 문자열을 받아서 UTC로 변환한 후 하루를 빼고 반환합니다. | ||
const BeforeDay = moment.tz(kstDate, 'Asia/Seoul').endOf('day').subtract(1, 'day') | ||
const BeforeDay = moment | ||
.tz(kstDate, "Asia/Seoul") | ||
.endOf("day") | ||
.subtract(1, "day"); | ||
return BeforeDay.utc().format(); | ||
} | ||
|
||
function getPreviousMonday(kstDate) { | ||
// 주어진 KST 날짜로부터 이전 주의 월요일을 찾음 | ||
const kstMoment = moment.tz(kstDate, "Asia/Seoul"); | ||
const dayOfWeek = kstMoment.day(); // 주어진 날짜의 요일 (0: 일요일, 1: 월요일, ..., 6: 토요일) | ||
|
||
// 월요일(1)에서 현재 요일을 뺀 만큼 이전 주의 월요일로 이동 | ||
const daysToPreviousMonday = dayOfWeek === 0 ? 6 : dayOfWeek - 1; | ||
const previousMonday = kstMoment.subtract(daysToPreviousMonday, "days"); | ||
|
||
// 이전 주의 월요일을 UTC로 변환하여 반환 | ||
return previousMonday.utc().format(); | ||
} | ||
|
||
module.exports = { | ||
convertKSTtoUTC, | ||
addEndTimeAndConvertToUTC, | ||
subtractOneDayAndConvertToUTC | ||
}; | ||
subtractOneDayAndConvertToUTC, | ||
getPreviousMonday, | ||
}; |
Oops, something went wrong.