Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main branch update from Dev branch #523

Merged
merged 38 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1e1a83f
Fix: change commitPayment and commitSettlement
chlehdwon Feb 12, 2024
35ff930
Merge branch 'dev' of https://github.com/sparcs-kaist/taxi-back into …
chlehdwon Mar 19, 2024
1bd982f
Refactor: validate by zod
chlehdwon Mar 19, 2024
295366c
Refactor: change settlement and payment
chlehdwon Mar 26, 2024
880aa3b
Add chatPaymentSettlementUpdater.js
chlehdwon Mar 26, 2024
2c06b1f
Fix: paymentHandler to commitPaymentHandler
chlehdwon Mar 26, 2024
b31b7b2
Fix: rooms.js comment
chlehdwon Mar 26, 2024
d1a04f5
Remove: comment in chatPaymentSettlementUpdater.js
chlehdwon Mar 28, 2024
d433687
Fix: test/rooms.js
chlehdwon Mar 28, 2024
f870b72
Merge branch 'dev' into #449-chat-validation
chlehdwon Apr 30, 2024
ce501cf
Add: Update Logic Change
happycastle114 May 7, 2024
c696d7c
Add: Logger
happycastle114 May 14, 2024
1f43d7a
Merge branch 'dev' into #449-chat-validation
chlehdwon May 14, 2024
e172852
Add: kaist info update
happycastle114 May 14, 2024
65c50ef
Fix: Change all field
happycastle114 May 14, 2024
e3a4ad6
Add: check whether user participated in rooms with send-required
chlehdwon May 20, 2024
1ba4833
Fix: remove async in checkIsSendRequired
chlehdwon May 20, 2024
dc99335
Add: isBanned, getBanned api implementation
TaehyeonPark May 20, 2024
0e63ae7
Add: swagger docs
TaehyeonPark May 20, 2024
9001413
Fix: swagger docs
TaehyeonPark May 20, 2024
28be0f0
Add: More logs
happycastle114 May 21, 2024
ea0e957
Merge pull request #518 from sparcs-kaist/#517-block-not-paid-user
chlehdwon May 21, 2024
ca94c72
Merge pull request #515 from sparcs-kaist/514-랜덤-이메일-업데이트
kmc7468 May 21, 2024
75b5314
Refactor: code convention and resolve comments
TaehyeonPark May 27, 2024
384b8d0
Merge branch 'dev' into #516-blockedlist
TaehyeonPark May 27, 2024
fc365c4
Refactor: resolve comments
TaehyeonPark May 27, 2024
2a2f3ab
Merge branch '#516-blockedlist' of https://github.com/sparcs-kaist/ta…
TaehyeonPark May 27, 2024
2bd12af
Refactor: resolve comments
TaehyeonPark May 27, 2024
323c09a
Fix: wrong comment
TaehyeonPark May 27, 2024
2cbdc29
Merge pull request #519 from sparcs-kaist/#516-blockedlist
TaehyeonPark May 27, 2024
f9eb601
Revert "#517 미정산 시 방 생성/참여 차단"
kmc7468 May 28, 2024
ad1af59
Merge pull request #521 from sparcs-kaist/revert-518-#517-block-not-p…
kmc7468 May 28, 2024
c654969
Merge branch 'dev' of https://github.com/sparcs-kaist/taxi-back into …
chlehdwon May 28, 2024
0a91f62
Fix: minor changes
chlehdwon May 28, 2024
9bb328c
Merge branch '#449-chat-validation' of https://github.com/sparcs-kais…
chlehdwon May 28, 2024
ef3cb81
Merge pull request #460 from sparcs-kaist/#449-chat-validation
chlehdwon May 28, 2024
6cedcf9
Fix: Change KAIST Info Mail
happycastle114 May 28, 2024
fb602a6
Merge pull request #522 from sparcs-kaist/514.1-KAIST-이메일-가져오기
kmc7468 May 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading