Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/sparcs-kaist/taxi-back into #…
Browse files Browse the repository at this point in the history
…273-안-읽은-메세지-확인
  • Loading branch information
chlehdwon committed Sep 17, 2023
2 parents d658d93 + 12d15d7 commit 8270cdd
Show file tree
Hide file tree
Showing 17 changed files with 562 additions and 180 deletions.
1 change: 1 addition & 0 deletions src/lottery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ lotteryRouter.use(require("../middlewares/originValidator"));
lotteryRouter.use("/global-state", require("./routes/globalState"));
lotteryRouter.use("/transactions", require("./routes/transactions"));
lotteryRouter.use("/items", require("./routes/items"));
lotteryRouter.use("/public-notice", require("./routes/publicNotice"));

const eventStatusResource = buildResource([instagramRewardAction])(
eventStatusModel
Expand Down
12 changes: 7 additions & 5 deletions src/lottery/modules/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const { eventEnv } = require("../../../loadenv");
/** eventId가 없는 경우 null이 아닌 undefined를 넣어야 합니다. */
const creditTransfer = async (userId, amount, eventId, comment) => {
const user = await useUserCreditAmount(userId);
await user.creditUpdate(amount);
await user.update(amount);

const transaction = new transactionModel({
type: "get",
amount,
userId,
eventId,
event: eventId,
comment,
});
await transaction.save();
Expand All @@ -21,15 +21,17 @@ const creditTransfer = async (userId, amount, eventId, comment) => {
};

/** itemId가 없는 경우 null이 아닌 undefined를 넣어야 합니다. */
const creditWithdraw = async (userId, amount, itemId, comment) => {
/** itemType이 없는 경우 null이 아닌 undefined를 넣어야 합니다. */
const creditWithdraw = async (userId, amount, itemId, itemType, comment) => {
const user = await useUserCreditAmount(userId);
await user.creditUpdate(-amount);
await user.update(-amount);

const transaction = new transactionModel({
type: "use",
amount,
userId,
itemId,
item: itemId,
itemType,
comment,
});
await transaction.save();
Expand Down
6 changes: 3 additions & 3 deletions src/lottery/modules/credit.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { eventStatusModel } = require("../modules/stores/mongo");

const useUserCreditAmount = async (userId) => {
const eventStatus = await eventStatusModel.findOne({ userId });
const eventStatus = await eventStatusModel.findOne({ userId }).lean();
if (!eventStatus) return null;

return {
creditAmount: eventStatus.creditAmount,
creditUpdate: async (delta) => {
amount: eventStatus.creditAmount,
update: async (delta) => {
await eventStatusModel.updateOne(
{ _id: eventStatus._id },
{
Expand Down
11 changes: 11 additions & 0 deletions src/lottery/modules/populates/transactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const transactionPopulateOption = [
{ path: "event" },
{
path: "item",
select: "name imageUrl price description isDisabled stock itemType",
},
];

module.exports = {
transactionPopulateOption,
};
28 changes: 26 additions & 2 deletions src/lottery/modules/stores/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ const eventStatusSchema = Schema({
min: 0,
validate: integerValidator,
},
ticket1Amount: {
type: Number,
default: 0,
min: 0,
validate: integerValidator,
},
ticket2Amount: {
type: Number,
default: 0,
min: 0,
validate: integerValidator,
},
});

const eventSchema = Schema({
Expand Down Expand Up @@ -50,6 +62,14 @@ const eventSchema = Schema({
type: Boolean,
default: false,
},
imageUrl: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
});

const itemSchema = Schema({
Expand Down Expand Up @@ -115,14 +135,18 @@ const transactionSchema = Schema({
ref: "User",
required: true,
},
eventId: {
event: {
type: Schema.Types.ObjectId,
ref: "Event",
},
itemId: {
item: {
type: Schema.Types.ObjectId,
ref: "Item",
},
itemType: {
type: Number,
enum: [0, 1, 2, 3],
},
comment: {
type: String,
required: true,
Expand Down
67 changes: 67 additions & 0 deletions src/lottery/routes/docs/eventsSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/** Event에 대한 기본적인 프로퍼티를 갖고 있는 스키마입니다. */
const eventBase = {
type: "object",
required: [
"_id",
"name",
"rewardAmount",
"maxCount",
"expireat",
"isDisabled",
"imageUrl",
"description",
],
properties: {
_id: {
type: "string",
description: "Event의 ObjectId",
example: "OBJECT ID",
},
name: {
type: "string",
description: "이벤트의 이름",
example: "최초 로그인 이벤트",
},
rewardAmount: {
type: "number",
description: "달성 보상",
example: 100,
},
maxCount: {
type: "number",
description: "최대 달성 가능 횟수",
example: 1,
},
expireat: {
type: "string",
description: "달성할 수 있는 마지막 시각",
example: "2023-01-01 00:00:00",
},
isDisabled: {
type: "boolean",
description: "달성 불가능 여부",
example: false,
},
imageUrl: {
type: "string",
description: "이미지 썸네일 URL",
example: "THUMBNAIL URL",
},
description: {
type: "string",
description: "이벤트의 설명",
example: "처음으로 이벤트 기간 중 Taxi에 로그인하면 송편을 드립니다.",
},
},
};

const eventsSchema = {
event: eventBase,
relatedEvent: {
...eventBase,
description:
"Transaction과 관련된 이벤트의 Object. 이벤트와 관련된 Transaction인 경우에만 포함됩니다.",
},
};

module.exports = eventsSchema;
19 changes: 17 additions & 2 deletions src/lottery/routes/docs/globalState.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ globalStateDocs[`${apiPrefix}/`] = {
"application/json": {
schema: {
type: "object",
required: [
"creditAmount",
"eventStatus",
"ticket1Amount",
"ticket2Amount",
"events",
],
properties: {
creditAmount: {
type: "number",
Expand All @@ -28,18 +35,26 @@ globalStateDocs[`${apiPrefix}/`] = {
items: {
type: "string",
description: "Event의 ObjectId",
example: "OBJECT ID",
},
},
ticket1Amount: {
type: "number",
description: "추첨권 (1)의 개수. 0 이상입니다.",
description: "일반 티켓의 개수. 0 이상입니다.",
example: 10,
},
ticket2Amount: {
type: "number",
description: "추첨권 (2)의 개수. 0 이상입니다.",
description: "고급 티켓의 개수. 0 이상입니다.",
example: 10,
},
events: {
type: "array",
description: "Event의 배열",
items: {
$ref: "#/components/schemas/event",
},
},
},
},
},
Expand Down
87 changes: 3 additions & 84 deletions src/lottery/routes/docs/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,13 @@ itemsDocs[`${apiPrefix}/list`] = {
"application/json": {
schema: {
type: "object",
required: ["items"],
properties: {
items: {
type: "array",
description: "Item의 배열",
items: {
type: "object",
properties: {
_id: {
type: "string",
description: "Item의 ObjectId",
example: "OBJECT ID",
},
name: {
type: "string",
description: "상품의 이름",
example: "랜덤 상자",
},
imageUrl: {
type: "string",
description: "이미지 썸네일 URL",
example: "THUMBNAIL URL",
},
price: {
type: "number",
description: "상품의 가격. 0 이상입니다.",
example: 400,
},
description: {
type: "string",
description: "상품의 설명",
example:
"랜덤으로 상품이 나오는 상자입니다. 확률은 다음과 같습니다: 진짜송편 100%, 치킨 0%, ...",
},
isDisabled: {
type: "boolean",
description: "판매 중지 여부",
example: false,
},
stock: {
type: "number",
description: "남은 상품 재고. 0 이상입니다.",
example: 10,
},
itemType: {
type: "number",
description:
"아이템 유형. 0: 티켓아님, 1:티켓 타입1, 2: 티켓 타입 2, 3: 랜덤박스",
example: 0,
},
},
$ref: "#/components/schemas/item",
},
},
},
Expand Down Expand Up @@ -95,45 +52,7 @@ itemsDocs[`${apiPrefix}/purchase/:itemId`] = {
example: true,
},
reward: {
type: "object",
description: "랜덤박스를 구입한 경우에만 포함됩니다.",
properties: {
_id: {
type: "string",
description: "Item의 ObjectId",
example: "OBJECT ID",
},
name: {
type: "string",
description: "상품의 이름",
example: "진짜송편",
},
imageUrl: {
type: "string",
description: "이미지 썸네일 URL",
example: "THUMBNAIL URL",
},
price: {
type: "number",
description: "상품의 가격. 0 이상입니다.",
example: 400,
},
description: {
type: "string",
description: "상품의 설명",
example: "맛있는 송편입니다.",
},
isDisabled: {
type: "boolean",
description: "판매 중지 여부",
example: false,
},
stock: {
type: "number",
description: "남은 상품 재고. 0 이상입니다.",
example: 10,
},
},
$ref: "#/components/schemas/rewardItem",
},
},
},
Expand Down
Loading

0 comments on commit 8270cdd

Please sign in to comment.