更新 src/services/guildService.ts
This commit is contained in:
parent
97f249ae8c
commit
cdb4032ba3
@ -1,7 +1,13 @@
|
||||
import { Request } from "express";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { addRecipes, getInventory } from "@/src/services/inventoryService";
|
||||
import { Guild, GuildMember, TGuildDatabaseDocument } from "@/src/models/guildModel";
|
||||
import {
|
||||
Guild,
|
||||
GuildLog,
|
||||
GuildMember,
|
||||
TGuildDatabaseDocument,
|
||||
TGuildLogDatabaseDocument
|
||||
} from "@/src/models/guildModel";
|
||||
import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
|
||||
import {
|
||||
IDojoClient,
|
||||
@ -329,3 +335,37 @@ export const createUniqueClanName = async (name: string): Promise<string> => {
|
||||
} while (discriminator != initialDiscriminator);
|
||||
throw new Error(`clan name is so unoriginal it's already been done 1000 times: ${name}`);
|
||||
};
|
||||
|
||||
export const getGuildLogForRequest = async (req: Request): Promise<TGuildLogDatabaseDocument> => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const inventory = await getInventory(accountId);
|
||||
const guildId = inventory.GuildId!.toString();
|
||||
const guildLog = await GuildLog.findOne({ _id: guildId });
|
||||
if (!guildLog) {
|
||||
throw new Error("Account thinks it is in a guild that doesn't exist");
|
||||
}
|
||||
return guildLog;
|
||||
};
|
||||
|
||||
export const getGuildLog = async (accountId: string, guild: TGuildDatabaseDocument) => {
|
||||
const guildLog = await GuildLog.findOne({ guildId: guild._id });
|
||||
if (!guildLog) {
|
||||
return await GuildLog.insertOne({
|
||||
_id: new Types.ObjectId(),
|
||||
accountId: accountId,
|
||||
guildId: guild._id,
|
||||
RoomChanges: [],
|
||||
TechChanges: [],
|
||||
RosterActivity: [],
|
||||
StandingsUpdates: [],
|
||||
ClassChanges: []
|
||||
});
|
||||
}
|
||||
return {
|
||||
RoomChanges: guildLog!.RoomChanges,
|
||||
TechChanges: guildLog!.TechChanges,
|
||||
RosterActivity: guildLog!.RosterActivity,
|
||||
StandingsUpdates: guildLog!.StandingsUpdates,
|
||||
ClassChanges: guildLog!.ClassChanges
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user