XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

feat: track RosterActivity in clan log (#1173)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1173

6508d161
Sainan <sainan@calamity.inc>
提交于

代码差异

5 个文件 +60 -15
Modified src/controllers/api/confirmGuildInvitationController.ts +19 -5
@@ -1,22 +1,36 @@
1 1 import { Guild, GuildMember } from "@/src/models/guildModel";
2 2 import { getGuildClient, updateInventoryForConfirmedGuildJoin } from "@/src/services/guildService";
3 import { getAccountIdForRequest } from "@/src/services/loginService";
3 import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
4 4 import { RequestHandler } from "express";
5 5 import { Types } from "mongoose";
6 6
7 7 export const confirmGuildInvitationController: RequestHandler = async (req, res) => {
8 const accountId = await getAccountIdForRequest(req);
8 const account = await getAccountForRequest(req);
9 9 const guildMember = await GuildMember.findOne({
10 accountId: accountId,
10 accountId: account._id,
11 11 guildId: req.query.clanId as string
12 12 });
13 13 if (guildMember) {
14 14 guildMember.status = 0;
15 15 await guildMember.save();
16 await updateInventoryForConfirmedGuildJoin(accountId, new Types.ObjectId(req.query.clanId as string));
16
17 await updateInventoryForConfirmedGuildJoin(
18 account._id.toString(),
19 new Types.ObjectId(req.query.clanId as string)
20 );
21
17 22 const guild = (await Guild.findOne({ _id: req.query.clanId as string }))!;
23
24 guild.RosterActivity ??= [];
25 guild.RosterActivity.push({
26 dateTime: new Date(),
27 entryType: 6,
28 details: getSuffixedName(account)
29 });
30 await guild.save();
31
18 32 res.json({
19 ...(await getGuildClient(guild, accountId)),
33 ...(await getGuildClient(guild, account._id.toString())),
20 34 InventoryChanges: {
21 35 Recipes: [
22 36 {
Modified src/controllers/api/getGuildLogController.ts +7 -0
@@ -25,6 +25,13 @@ export const getGuildLogController: RequestHandler = async (req, res) => {
25 25 details: entry.details
26 26 });
27 27 });
28 guild.RosterActivity?.forEach(entry => {
29 log.RosterActivity.push({
30 dateTime: toMongoDate(entry.dateTime),
31 entryType: entry.entryType,
32 details: entry.details
33 });
34 });
28 35 guild.ClassChanges?.forEach(entry => {
29 36 log.ClassChanges.push({
30 37 dateTime: toMongoDate(entry.dateTime),
Modified src/controllers/api/removeFromGuildController.ts +22 -0
@@ -1,9 +1,12 @@
1 1 import { GuildMember } from "@/src/models/guildModel";
2 import { Account } from "@/src/models/loginModel";
2 3 import { getGuildForRequest } from "@/src/services/guildService";
3 4 import { getInventory } from "@/src/services/inventoryService";
5 import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
4 6 import { RequestHandler } from "express";
5 7
6 8 export const removeFromGuildController: RequestHandler = async (req, res) => {
9 const account = await getAccountForRequest(req);
7 10 const guild = await getGuildForRequest(req);
8 11 // TODO: Check permissions
9 12 const payload = JSON.parse(String(req.body)) as IRemoveFromGuildRequest;
@@ -32,6 +35,25 @@ export const removeFromGuildController: RequestHandler = async (req, res) => {
32 35 }
33 36 await GuildMember.deleteOne({ _id: guildMember._id });
34 37
38 guild.RosterActivity ??= [];
39 if (account._id.equals(payload.userId)) {
40 // Leave
41 guild.RosterActivity.push({
42 dateTime: new Date(),
43 entryType: 7,
44 details: getSuffixedName(account)
45 });
46 } else {
47 // Kick
48 const kickee = (await Account.findOne({ _id: payload.userId }))!;
49 guild.RosterActivity.push({
50 dateTime: new Date(),
51 entryType: 12,
52 details: getSuffixedName(kickee) + "," + getSuffixedName(account)
53 });
54 }
55 await guild.save();
56
35 57 res.json({
36 58 _id: payload.userId,
37 59 ItemToRemove: "/Lotus/Types/Keys/DojoKey",
Modified src/models/guildModel.ts +7 -6
@@ -5,8 +5,8 @@ import {
5 5 IDojoDecoDatabase,
6 6 ILongMOTD,
7 7 IGuildMemberDatabase,
8 IGuildLogClassChange,
9 IGuildLogTechChange,
8 IGuildLogEntryNumber,
9 IGuildLogEntryString,
10 10 IGuildRank
11 11 } from "@/src/types/guildTypes";
12 12 import { Document, Model, model, Schema, Types } from "mongoose";
@@ -106,7 +106,7 @@ const defaultRanks: IGuildRank[] = [
106 106 }
107 107 ];
108 108
109 const guildLogTechChangeSchema = new Schema<IGuildLogTechChange>(
109 const guildLogEntryStringSchema = new Schema<IGuildLogEntryString>(
110 110 {
111 111 dateTime: Date,
112 112 entryType: Number,
@@ -115,7 +115,7 @@ const guildLogTechChangeSchema = new Schema<IGuildLogTechChange>(
115 115 { _id: false }
116 116 );
117 117
118 const guildLogClassChangeSchema = new Schema<IGuildLogClassChange>(
118 const guildLogEntryNumberSchema = new Schema<IGuildLogEntryNumber>(
119 119 {
120 120 dateTime: Date,
121 121 entryType: Number,
@@ -146,8 +146,9 @@ const guildSchema = new Schema<IGuildDatabase>(
146 146 CeremonyContributors: { type: [Types.ObjectId], default: undefined },
147 147 CeremonyResetDate: Date,
148 148 CeremonyEndo: Number,
149 TechChanges: { type: [guildLogTechChangeSchema], default: undefined },
150 ClassChanges: { type: [guildLogClassChangeSchema], default: undefined }
149 TechChanges: { type: [guildLogEntryStringSchema], default: undefined },
150 RosterActivity: { type: [guildLogEntryStringSchema], default: undefined },
151 ClassChanges: { type: [guildLogEntryNumberSchema], default: undefined }
151 152 },
152 153 { id: false }
153 154 );
Modified src/types/guildTypes.ts +5 -4
@@ -48,8 +48,9 @@ export interface IGuildDatabase {
48 48 CeremonyContributors?: Types.ObjectId[];
49 49 CeremonyResetDate?: Date;
50 50
51 TechChanges?: IGuildLogTechChange[];
52 ClassChanges?: IGuildLogClassChange[];
51 TechChanges?: IGuildLogEntryString[];
52 RosterActivity?: IGuildLogEntryString[];
53 ClassChanges?: IGuildLogEntryNumber[];
53 54 }
54 55
55 56 export interface ILongMOTD {
@@ -186,13 +187,13 @@ export interface ITechProjectDatabase extends Omit<ITechProjectClient, "Completi
186 187 CompletionDate?: Date;
187 188 }
188 189
189 export interface IGuildLogTechChange {
190 export interface IGuildLogEntryString {
190 191 dateTime: Date;
191 192 entryType: number;
192 193 details: string;
193 194 }
194 195
195 export interface IGuildLogClassChange {
196 export interface IGuildLogEntryNumber {
196 197 dateTime: Date;
197 198 entryType: number;
198 199 details: number;