feat: track RosterActivity in clan log
All checks were successful
Build / build (22) (push) Successful in 43s
Build / build (18) (push) Successful in 1m6s
Build / build (20) (push) Successful in 59s
Build / build (18) (pull_request) Successful in 44s
Build / build (20) (pull_request) Successful in 1m8s
Build / build (22) (pull_request) Successful in 56s
All checks were successful
Build / build (22) (push) Successful in 43s
Build / build (18) (push) Successful in 1m6s
Build / build (20) (push) Successful in 59s
Build / build (18) (pull_request) Successful in 44s
Build / build (20) (pull_request) Successful in 1m8s
Build / build (22) (pull_request) Successful in 56s
This commit is contained in:
parent
3a995ef6d1
commit
d04d4cce34
@ -1,22 +1,36 @@
|
||||
import { Guild, GuildMember } from "@/src/models/guildModel";
|
||||
import { getGuildClient, updateInventoryForConfirmedGuildJoin } from "@/src/services/guildService";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
|
||||
import { RequestHandler } from "express";
|
||||
import { Types } from "mongoose";
|
||||
|
||||
export const confirmGuildInvitationController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const account = await getAccountForRequest(req);
|
||||
const guildMember = await GuildMember.findOne({
|
||||
accountId: accountId,
|
||||
accountId: account._id,
|
||||
guildId: req.query.clanId as string
|
||||
});
|
||||
if (guildMember) {
|
||||
guildMember.status = 0;
|
||||
await guildMember.save();
|
||||
await updateInventoryForConfirmedGuildJoin(accountId, new Types.ObjectId(req.query.clanId as string));
|
||||
|
||||
await updateInventoryForConfirmedGuildJoin(
|
||||
account._id.toString(),
|
||||
new Types.ObjectId(req.query.clanId as string)
|
||||
);
|
||||
|
||||
const guild = (await Guild.findOne({ _id: req.query.clanId as string }))!;
|
||||
|
||||
guild.RosterActivity ??= [];
|
||||
guild.RosterActivity.push({
|
||||
dateTime: new Date(),
|
||||
entryType: 6,
|
||||
details: getSuffixedName(account)
|
||||
});
|
||||
await guild.save();
|
||||
|
||||
res.json({
|
||||
...(await getGuildClient(guild, accountId)),
|
||||
...(await getGuildClient(guild, account._id.toString())),
|
||||
InventoryChanges: {
|
||||
Recipes: [
|
||||
{
|
||||
|
@ -25,6 +25,13 @@ export const getGuildLogController: RequestHandler = async (req, res) => {
|
||||
details: entry.details
|
||||
});
|
||||
});
|
||||
guild.RosterActivity?.forEach(entry => {
|
||||
log.RosterActivity.push({
|
||||
dateTime: toMongoDate(entry.dateTime),
|
||||
entryType: entry.entryType,
|
||||
details: entry.details
|
||||
});
|
||||
});
|
||||
guild.ClassChanges?.forEach(entry => {
|
||||
log.ClassChanges.push({
|
||||
dateTime: toMongoDate(entry.dateTime),
|
||||
|
@ -1,9 +1,12 @@
|
||||
import { GuildMember } from "@/src/models/guildModel";
|
||||
import { Account } from "@/src/models/loginModel";
|
||||
import { getGuildForRequest } from "@/src/services/guildService";
|
||||
import { getInventory } from "@/src/services/inventoryService";
|
||||
import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
export const removeFromGuildController: RequestHandler = async (req, res) => {
|
||||
const account = await getAccountForRequest(req);
|
||||
const guild = await getGuildForRequest(req);
|
||||
// TODO: Check permissions
|
||||
const payload = JSON.parse(String(req.body)) as IRemoveFromGuildRequest;
|
||||
@ -32,6 +35,25 @@ export const removeFromGuildController: RequestHandler = async (req, res) => {
|
||||
}
|
||||
await GuildMember.deleteOne({ _id: guildMember._id });
|
||||
|
||||
guild.RosterActivity ??= [];
|
||||
if (account._id.equals(payload.userId)) {
|
||||
// Leave
|
||||
guild.RosterActivity.push({
|
||||
dateTime: new Date(),
|
||||
entryType: 7,
|
||||
details: getSuffixedName(account)
|
||||
});
|
||||
} else {
|
||||
// Kick
|
||||
const kickee = (await Account.findOne({ _id: payload.userId }))!;
|
||||
guild.RosterActivity.push({
|
||||
dateTime: new Date(),
|
||||
entryType: 12,
|
||||
details: getSuffixedName(kickee) + "," + getSuffixedName(account)
|
||||
});
|
||||
}
|
||||
await guild.save();
|
||||
|
||||
res.json({
|
||||
_id: payload.userId,
|
||||
ItemToRemove: "/Lotus/Types/Keys/DojoKey",
|
||||
|
@ -5,8 +5,8 @@ import {
|
||||
IDojoDecoDatabase,
|
||||
ILongMOTD,
|
||||
IGuildMemberDatabase,
|
||||
IGuildLogClassChange,
|
||||
IGuildLogTechChange,
|
||||
IGuildLogEntryNumber,
|
||||
IGuildLogEntryString,
|
||||
IGuildRank
|
||||
} from "@/src/types/guildTypes";
|
||||
import { Document, Model, model, Schema, Types } from "mongoose";
|
||||
@ -106,7 +106,7 @@ const defaultRanks: IGuildRank[] = [
|
||||
}
|
||||
];
|
||||
|
||||
const guildLogTechChangeSchema = new Schema<IGuildLogTechChange>(
|
||||
const guildLogEntryStringSchema = new Schema<IGuildLogEntryString>(
|
||||
{
|
||||
dateTime: Date,
|
||||
entryType: Number,
|
||||
@ -115,7 +115,7 @@ const guildLogTechChangeSchema = new Schema<IGuildLogTechChange>(
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
const guildLogClassChangeSchema = new Schema<IGuildLogClassChange>(
|
||||
const guildLogEntryNumberSchema = new Schema<IGuildLogEntryNumber>(
|
||||
{
|
||||
dateTime: Date,
|
||||
entryType: Number,
|
||||
@ -146,8 +146,9 @@ const guildSchema = new Schema<IGuildDatabase>(
|
||||
CeremonyContributors: { type: [Types.ObjectId], default: undefined },
|
||||
CeremonyResetDate: Date,
|
||||
CeremonyEndo: Number,
|
||||
TechChanges: { type: [guildLogTechChangeSchema], default: undefined },
|
||||
ClassChanges: { type: [guildLogClassChangeSchema], default: undefined }
|
||||
TechChanges: { type: [guildLogEntryStringSchema], default: undefined },
|
||||
RosterActivity: { type: [guildLogEntryStringSchema], default: undefined },
|
||||
ClassChanges: { type: [guildLogEntryNumberSchema], default: undefined }
|
||||
},
|
||||
{ id: false }
|
||||
);
|
||||
|
@ -48,8 +48,9 @@ export interface IGuildDatabase {
|
||||
CeremonyContributors?: Types.ObjectId[];
|
||||
CeremonyResetDate?: Date;
|
||||
|
||||
TechChanges?: IGuildLogTechChange[];
|
||||
ClassChanges?: IGuildLogClassChange[];
|
||||
TechChanges?: IGuildLogEntryString[];
|
||||
RosterActivity?: IGuildLogEntryString[];
|
||||
ClassChanges?: IGuildLogEntryNumber[];
|
||||
}
|
||||
|
||||
export interface ILongMOTD {
|
||||
@ -186,13 +187,13 @@ export interface ITechProjectDatabase extends Omit<ITechProjectClient, "Completi
|
||||
CompletionDate?: Date;
|
||||
}
|
||||
|
||||
export interface IGuildLogTechChange {
|
||||
export interface IGuildLogEntryString {
|
||||
dateTime: Date;
|
||||
entryType: number;
|
||||
details: string;
|
||||
}
|
||||
|
||||
export interface IGuildLogClassChange {
|
||||
export interface IGuildLogEntryNumber {
|
||||
dateTime: Date;
|
||||
entryType: number;
|
||||
details: number;
|
||||
|
Loading…
x
Reference in New Issue
Block a user