Skip to content

Commit

Permalink
Merge pull request #523 from sparcs-kaist/dev
Browse files Browse the repository at this point in the history
Main branch update from Dev branch
  • Loading branch information
kmc7468 authored May 28, 2024
2 parents 80e3e45 + fb602a6 commit df7771e
Show file tree
Hide file tree
Showing 15 changed files with 319 additions and 50 deletions.
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!");
});
6 changes: 3 additions & 3 deletions src/lottery/modules/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const completeFirstLoginQuest = async (userId, timestamp) => {
* @param {Date} roomObject.time - 출발 시각입니다.
* @returns {Promise}
* @description 정산 요청 또는 송금이 이루어질 때마다 호출해 주세요.
* @usage rooms - commitPaymentHandler, rooms - settlementHandler
* @usage rooms - commitSettlementHandler, rooms - commitPaymentHandler
*/
const completePayingAndSendingQuest = async (userId, timestamp, roomObject) => {
logger.info(
Expand Down Expand Up @@ -167,7 +167,7 @@ const completeFirstRoomCreationQuest = async (userId, timestamp) => {
* @param {Date} roomObject.time - 출발 시각입니다.
* @returns {Promise}
* @description 정산 요청이 이루어질 때마다 호출해 주세요.
* @usage rooms - commitPaymentHandler
* @usage rooms - commitSettlementHandler
*/
const completePayingQuest = async (userId, timestamp, roomObject) => {
logger.info(
Expand Down Expand Up @@ -195,7 +195,7 @@ const completePayingQuest = async (userId, timestamp, roomObject) => {
* @param {Date} roomObject.time - 출발 시각입니다.
* @returns {Promise}
* @description 송금이 이루어질 때마다 호출해 주세요.
* @usage rooms - settlementHandler
* @usage rooms - commitPaymentHandler
*/
const completeSendingQuest = async (userId, timestamp, roomObject) => {
logger.info(
Expand Down
4 changes: 2 additions & 2 deletions src/modules/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ const getMessageBody = (type, nickname = "", content = "") => {
const suffix = "님이 퇴장하였습니다";
return `${ellipsisedNickname} ${suffix}`;
}
case "payment": {
case "settlement": {
const suffix = "님이 정산을 시작하였습니다";
return `${ellipsisedNickname} ${suffix}`;
}
case "settlement": {
case "payment": {
const suffix = "님이 송금을 완료하였습니다";
return `${ellipsisedNickname} ${suffix}`;
}
Expand Down
34 changes: 34 additions & 0 deletions src/modules/stores/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,39 @@ const userSchema = Schema({
account: { type: String, default: "" }, //계좌번호 정보
});

const banSchema = Schema({
// 정지 시킬 사용자를 기제함.
userId: { type: mongoose.Types.ObjectId, ref: "User", required: true },
// 정지 사유
reason: {
type: String,
required: true,
},
bannedAt: {
type: Date, // 정지 당한 시각
required: true,
},
expireAt: {
type: Date, // 정지 만료 시각
required: true,
},
services: [
{
// 정지를 당한 서비스를 기제함
serviceName: {
type: String,
required: true,
// 필요시 이곳에 정지를 시킬 서비스를 추가함.
enum: [
"all", // all -> 과거/미래 모든 서비스 및 이벤트 이용 제한
"service", // service -> 방 생성/참여 제한
"2023-fall-event", // event -> 특정 이벤트 참여 제한
],
},
},
],
});

const participantSchema = Schema({
user: { type: Schema.Types.ObjectId, ref: "User", required: true },
settlementStatus: {
Expand Down Expand Up @@ -207,6 +240,7 @@ const connectDatabase = (mongoUrl) => {
module.exports = {
connectDatabase,
userModel: mongoose.model("User", userSchema),
banModel: mongoose.model("Ban", banSchema),
deviceTokenModel: mongoose.model("DeviceToken", deviceTokenSchema),
notificationOptionModel: mongoose.model(
"NotificationOption",
Expand Down
2 changes: 2 additions & 0 deletions src/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const AdminJSExpress = require("@adminjs/express");
const AdminJSMongoose = require("@adminjs/mongoose");
const {
userModel,
banModel,
roomModel,
locationModel,
chatModel,
Expand All @@ -26,6 +27,7 @@ AdminJS.registerAdapter(AdminJSMongoose);

const resources = [
userModel,
banModel,
roomModel,
locationModel,
chatModel,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/docs/chats.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ chatsDocs[`${apiPrefix}/send`] = {
Chat {
roomId: ObjectId, //방의 objectId
type: String, // 메시지 종류 ("text": 일반 메시지, "s3img": S3에 업로드된 이미지, "in": 입장 메시지, "out": 퇴장 메시지, "payment": 결제 메시지, "settlement": 정산 완료 메시지, "account": 계좌 전송 메시지)
type: String, // 메시지 종류 ("text": 일반 메시지, "s3img": S3에 업로드된 이미지, "in": 입장 메시지, "out": 퇴장 메시지, "settlement": 정산 메시지, "payment": 송금 메시지, "account": 계좌 전송 메시지)
authorId: ObejctId, //작성자의 objectId
content: String, // 메시지 내용 (메시지 종류에 따라 포맷이 상이함)
time: String(ISO 8601), // ex) 2024-01-08T01:52:00.000Z
Expand Down
20 changes: 10 additions & 10 deletions src/routes/docs/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,11 +683,11 @@ roomsDocs[`${apiPrefix}/searchByUser`] = {
},
};

roomsDocs[`${apiPrefix}/commitPayment`] = {
roomsDocs[`${apiPrefix}/commitSettlement`] = {
post: {
tags: [tag],
summary: "방 결제 처리",
description: `해당 방에 요청을 보낸 유저를 결제자로 처리합니다.<br/>
summary: "방 정산 요청 처리",
description: `해당 방에 요청을 보낸 유저를 결제자로 처리하여, 다른 유저들에게 정산을 요청합니다.<br/>
이미 출발한 방에 대해서만 요청을 처리합니다.<br/>
방의 \`part\` 배열에서 요청을 보낸 유저의 \`isSettlement\` 속성은 \`paid\`로 설정됩니다.<br/>
나머지 유저들의 \`isSettlement\` 속성을 \`send-required\`로 설정합니다.`,
Expand Down Expand Up @@ -731,7 +731,7 @@ roomsDocs[`${apiPrefix}/commitPayment`] = {
},
},
example: {
error: "Rooms/:id/commitPayment : cannot find settlement info",
error: "Rooms/:id/commitSettlement : cannot find settlement info",
},
},
},
Expand All @@ -749,7 +749,7 @@ roomsDocs[`${apiPrefix}/commitPayment`] = {
},
},
example: {
error: "Rooms/:id/commitPayment : internal server error",
error: "Rooms/:id/commitSettlement : internal server error",
},
},
},
Expand All @@ -758,11 +758,11 @@ roomsDocs[`${apiPrefix}/commitPayment`] = {
},
};

roomsDocs[`${apiPrefix}/commitSettlement`] = {
roomsDocs[`${apiPrefix}/commitPayment`] = {
post: {
tags: [tag],
summary: "방 정산 완료 처리",
description: `해당 방에 요청을 보낸 유저를 정산 완료로 처리합니다.<br/>
summary: "방 송금 처리",
description: `해당 방에 요청을 보낸 유저를 송금을 완료한 정산 완료로 처리합니다.<br/>
방의 \`part\` 배열에서 요청을 보낸 유저의 \`isSettlement\` 속성은 \`send-required\`에서 \`sent\`로 변경합니다.<br/>
방의 참여한 유저들이 모두 정산완료를 하면 방의 \`isOver\` 속성이 \`true\`로 변경되며, 과거 방으로 취급됩니다.`,
requestBody: {
Expand Down Expand Up @@ -805,7 +805,7 @@ roomsDocs[`${apiPrefix}/commitSettlement`] = {
},
},
example: {
error: "Rooms/:id/settlement : cannot find settlement info",
error: "Rooms/:id/commitPayment : cannot find settlement info",
},
},
},
Expand All @@ -823,7 +823,7 @@ roomsDocs[`${apiPrefix}/commitSettlement`] = {
},
},
example: {
error: "Rooms/:id/settlement : internal server error",
error: "Rooms/:id/commitPayment : internal server error",
},
},
},
Expand Down
8 changes: 8 additions & 0 deletions src/routes/docs/schemas/roomsSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ roomsZod["room"] = z
})
.partial({ settlementTotal: true, isOver: true });

roomsZod["commitSettlement"] = z.object({
roomId: z.string().regex(objectId),
});

roomsZod["commitPayment"] = z.object({
roomId: z.string().regex(objectId),
});

const roomsSchema = zodToSchemaObject(roomsZod);

module.exports = { roomsSchema, roomsZod };
139 changes: 139 additions & 0 deletions src/routes/docs/users.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const tag = "users";
const apiPrefix = "/users";
const { objectId } = require("../../modules/patterns");

const usersDocs = {};
usersDocs[`${apiPrefix}/agreeOnTermsOfService`] = {
Expand Down Expand Up @@ -329,4 +330,142 @@ usersDocs[`${apiPrefix}/resetProfileImg`] = {
},
};

usersDocs[`${apiPrefix}/isBanned`] = {
get: {
tags: [tag],
summary: "본인의 현재 정지 기록을 가져움",
description:
"정지 기록들 중 본인이고, 서버 시간을 기준으로 expireAt 보다 작은 경우에 해당하는 정지 기록을 모두 가져옴",
responses: {
200: {
content: {
"application/json": {
schema: {
type: "array",
items: {
properties: {
userId: {
type: "string",
description: "사용자의 ObjectId",
pattern: objectId.source,
},
reason: {
type: "string",
description: "정지 사유",
example: "미정산",
},
bannedAt: {
type: "date",
description: "정지 당한 시각",
example: "2024-05-20 12:00",
},
expireAt: {
type: "date",
description: "정지 만료 시각",
example: "2024-05-21 12:00",
},
services: {
type: "array",
items: {
properties: {
serviceName: {
type: "string",
description: "정지를 당한 서비스 또는 이벤트 이름",
},
},
},
},
},
},
},
},
},
},
400: {
content: {
"text/html": {
example: "Users/isBanned : there is no ban record",
},
},
},
500: {
content: {
"text/html": {
example: "Users/isBanned : internal server error",
},
},
},
},
},
};

usersDocs[`${apiPrefix}/getBanRecord`] = {
get: {
tags: [tag],
summary: "본인의 모든 정지 기록을 가져움",
description:
"정지 기록들 중 본인인 경우에 해당하는 정지 기록을 모두 가져옴",
responses: {
200: {
content: {
"application/json": {
schema: {
type: "array",
items: {
properties: {
userId: {
type: "string",
description: "사용자의 ObjectId",
pattern: objectId.source,
},
reason: {
type: "string",
description: "정지 사유",
example: "미정산",
},
bannedAt: {
type: "date",
description: "정지 당한 시각",
example: "2024-05-20 12:00",
},
expireAt: {
type: "date",
description: "정지 만료 시각",
example: "2024-05-21 12:00",
},
services: {
type: "array",
items: {
properties: {
serviceName: {
type: "string",
description: "정지를 당한 서비스 또는 이벤트 이름",
},
},
},
},
},
},
},
},
},
},
400: {
content: {
"text/html": {
example: "Users/getBanRecord : there is no ban record",
},
},
},
500: {
content: {
"text/html": {
example: "Users/getBanRecord : internal server error",
},
},
},
},
},
};

module.exports = usersDocs;
Loading

0 comments on commit df7771e

Please sign in to comment.