Skip to content

Commit

Permalink
Merge branch 'dev' into #159-add-typescript-support
Browse files Browse the repository at this point in the history
Compile errors will be fixed later
  • Loading branch information
kmc7468 committed Nov 12, 2024
2 parents a6db7d9 + f89a1ab commit dd6e851
Show file tree
Hide file tree
Showing 62 changed files with 2,005 additions and 939 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CORS_WHITELIST=[CORS 정책에서 허용하는 도메인의 목록(e.g. ["http:/
GOOGLE_APPLICATION_CREDENTIALS=[GOOGLE_APPLICATION_CREDENTIALS JSON]
TEST_ACCOUNTS=[스팍스SSO로 로그인시 무조건 테스트로 로그인이 가능한 허용 아이디 목록]
SLACK_REPORT_WEBHOOK_URL=[Slack 웹훅 URL들이 담긴 JSON]
NAVER_MAP_API_ID=[네이버 지도 API ID]
NAVER_MAP_API_KEY=[네이버 지도 API KEY]

# optional environment variables for taxiSampleGenerator
SAMPLE_NUM_OF_ROOMS=[방의 개수]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"express-rate-limit": "^7.1.0",
"express-session": "^1.17.3",
"express-validator": "^6.14.0",
"firebase-admin": "^11.4.1",
"firebase-admin": "^11.11.1",
"jsonwebtoken": "^9.0.2",
"mongoose": "^6.12.0",
"node-cron": "3.0.2",
Expand Down
10 changes: 6 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions scripts/chatPaymentSettlementUpdater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Issue #449-1을 해결하기 위한 DB 마이그레이션 스크립트입니다.
// chat type 중 settlement와 payment를 서로 교체합니다.
// https://github.com/sparcs-kaist/taxi-back/issues/449

const { MongoClient } = require("mongodb");
const { mongo: mongoUrl } = require("../loadenv");

const client = new MongoClient(mongoUrl);
const db = client.db("taxi");
const chats = db.collection("chats");

async function run() {
try {
for await (const doc of chats.find()) {
if (doc.type === "settlement" || doc.type === "payment") {
await chats.findOneAndUpdate(
{ _id: doc._id },
{
$set: {
type: doc.type === "settlement" ? "payment" : "settlement",
},
}
);
}
}
} catch (err) {
console.log(err);
} finally {
await client.close();
}
}
run().then(() => {
console.log("Done!");
});
4 changes: 2 additions & 2 deletions src/lottery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ lotteryRouter.use(require("../middlewares/originValidator"));

// [Router] APIs
lotteryRouter.use("/globalState", require("./routes/globalState"));
lotteryRouter.use("/invite", require("./routes/invite"));
lotteryRouter.use("/invites", require("./routes/invites"));
lotteryRouter.use("/transactions", require("./routes/transactions"));
lotteryRouter.use("/items", require("./routes/items"));
lotteryRouter.use("/publicNotice", require("./routes/publicNotice"));
// lotteryRouter.use("/publicNotice", require("./routes/publicNotice"));
lotteryRouter.use("/quests", require("./routes/quests"));

// [AdminJS] AdminJS에 표시할 Resource 생성
Expand Down
182 changes: 76 additions & 106 deletions src/lottery/modules/contracts.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/lottery/modules/populates/transactions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const transactionPopulateOption = [
{
path: "item",
select:
"name imageUrl instagramStoryStickerImageUrl price description isDisabled stock itemType",
path: "itemId",
select: "name imageUrl",
},
];

Expand Down
12 changes: 8 additions & 4 deletions src/lottery/modules/quests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const eventPeriod = eventConfig && {
};

const requiredQuestFields = ["name", "description", "imageUrl", "reward"];

const buildQuests = (quests) => {
for (const [id, quest] of Object.entries(quests)) {
// quest에 필수 필드가 모두 포함되어 있는지 확인합니다.
Expand Down Expand Up @@ -61,7 +62,7 @@ const buildQuests = (quests) => {
* @param {number} quest.reward.credit - 퀘스트의 완료 보상 중 재화의 양입니다.
* @param {number} quest.reward.ticket1 - 퀘스트의 완료 보상 중 일반 티켓의 개수입니다.
* @param {number} quest.maxCount - 퀘스트의 최대 완료 가능 횟수입니다.
* @returns {Object|null} 성공한 경우 Object를, 실패한 경우 null을 반환합니다. 이미 최대 완료 횟수에 도달했거나, 퀘스트가 원격으로 비활성화 된 경우에도 실패로 처리됩니다.
* @returns {Object|null} 성공한 경우 Object를, 실패한 경우 null을 반환합니다. 이미 최대 완료 횟수에 도달했거나, 퀘스트가 원격으로 비활성화된 경우에도 실패로 처리됩니다.
*/
const completeQuest = async (userId, timestamp, quest) => {
try {
Expand All @@ -84,7 +85,7 @@ const completeQuest = async (userId, timestamp, quest) => {
// 3단계: 유저의 퀘스트 완료 횟수를 확인합니다.
// maxCount가 0인 경우, 무제한으로 퀘스트를 완료할 수 있습니다.
const questCount = eventStatus.completedQuests.filter(
(completedQuestId) => completedQuestId === quest.id
({ questId }) => questId === quest.id
).length;
if (quest.maxCount > 0 && questCount >= quest.maxCount) {
logger.info(
Expand Down Expand Up @@ -118,7 +119,10 @@ const completeQuest = async (userId, timestamp, quest) => {
ticket1Amount: quest.reward.ticket1,
},
$push: {
completedQuests: quest.id,
completedQuests: {
questId: quest.id,
completedAt: timestamp,
},
},
}
);
Expand All @@ -143,7 +147,7 @@ const completeQuest = async (userId, timestamp, quest) => {
amount: 0,
userId,
questId: quest.id,
item: ticket1._id,
itemId: ticket1._id,
comment: `"${quest.name}" 퀘스트를 완료해 "${ticket1.name}" ${quest.reward.ticket1}개를 획득했습니다.`,
});
await transaction.save();
Expand Down
48 changes: 30 additions & 18 deletions src/lottery/modules/stores/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@ const integerValidator = {
message: "{VALUE} is not an integer value",
};

const completedQuestSchema = Schema({
questId: {
type: String,
required: true,
},
completedAt: {
type: Date,
required: true,
},
});

const eventStatusSchema = Schema({
userId: {
type: Schema.Types.ObjectId,
ref: "User",
required: true,
},
completedQuests: {
type: [String],
type: [completedQuestSchema],
default: [],
},
creditAmount: {
Expand All @@ -42,17 +53,11 @@ const eventStatusSchema = Schema({
type: Boolean,
default: false,
},
group: {
type: Number,
required: true,
min: 1,
validate: integerValidator,
}, // 소속된 새터반
inviter: {
type: Schema.Types.ObjectId,
ref: "User",
}, // 이 사용자를 초대한 사용자
isEnabledInviteUrl: {
isInviteUrlEnabled: {
type: Boolean,
default: false,
}, // 초대 링크 활성화 여부
Expand Down Expand Up @@ -101,7 +106,13 @@ const itemSchema = Schema({
required: true,
min: 0,
validate: integerValidator,
},
}, // 의미 없는 값, 기존 코드와의 호환성을 위해 남겨둡니다.
realStock: {
type: Number,
required: true,
min: 1,
validate: integerValidator,
}, // 상품의 실제 재고
itemType: {
type: Number,
enum: [0, 1, 2, 3],
Expand All @@ -124,36 +135,37 @@ const transactionSchema = Schema({
type: String,
enum: ["get", "use"],
required: true,
},
}, // get: 재화 획득, use: 재화 사용
amount: {
type: Number,
required: true,
min: 0,
validate: integerValidator,
},
}, // 재화의 변화량의 절댓값
userId: {
type: Schema.Types.ObjectId,
ref: "User",
required: true,
},
questId: {
type: String,
},
item: {
}, // 완료한 퀘스트의 ID
itemId: {
type: Schema.Types.ObjectId,
ref: `${modelNamePrefix}Item`,
},
itemType: {
}, // 획득한 상품의 ID
itemAmount: {
type: Number,
enum: [0, 1, 2, 3],
},
min: 1,
validate: integerValidator,
}, // 획득한 상품의 개수
comment: {
type: String,
required: true,
},
});
transactionSchema.set("timestamps", {
createdAt: "createAt",
createdAt: "createdAt",
updatedAt: false,
});

Expand Down
Loading

0 comments on commit dd6e851

Please sign in to comment.