add GuildMember model
This commit is contained in:
		
							parent
							
								
									b0b52ccabe
								
							
						
					
					
						commit
						e8bd9e4ec4
					
				@ -2,7 +2,7 @@ import { RequestHandler } from "express";
 | 
				
			|||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
					import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
				
			||||||
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
 | 
					import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
 | 
				
			||||||
import { Guild } from "@/src/models/guildModel";
 | 
					import { Guild, GuildMember } from "@/src/models/guildModel";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const createGuildController: RequestHandler = async (req, res) => {
 | 
					export const createGuildController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
@ -14,6 +14,14 @@ export const createGuildController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
    await guild.save();
 | 
					    await guild.save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Create guild member on database
 | 
				
			||||||
 | 
					    await GuildMember.insertOne({
 | 
				
			||||||
 | 
					        accountId: accountId,
 | 
				
			||||||
 | 
					        guildId: guild._id,
 | 
				
			||||||
 | 
					        status: 0,
 | 
				
			||||||
 | 
					        rank: 0
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Update inventory
 | 
					    // Update inventory
 | 
				
			||||||
    const inventory = await Inventory.findOne({ accountOwnerId: accountId });
 | 
					    const inventory = await Inventory.findOne({ accountOwnerId: accountId });
 | 
				
			||||||
    if (inventory) {
 | 
					    if (inventory) {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,6 @@
 | 
				
			|||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
 | 
					import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
 | 
				
			||||||
import { Guild } from "@/src/models/guildModel";
 | 
					import { Guild, GuildMember } from "@/src/models/guildModel";
 | 
				
			||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
 | 
					import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
 | 
				
			||||||
import { getGuildVault } from "@/src/services/guildService";
 | 
					import { getGuildVault } from "@/src/services/guildService";
 | 
				
			||||||
@ -23,6 +23,24 @@ const getGuildController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
                guild.CeremonyResetDate = undefined;
 | 
					                guild.CeremonyResetDate = undefined;
 | 
				
			||||||
                await guild.save();
 | 
					                await guild.save();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            const guildMembers = await GuildMember.find({ guildId: inventory.GuildId });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Handle clans created prior to creation of the GuildMember model.
 | 
				
			||||||
 | 
					            let missingEntry = true;
 | 
				
			||||||
 | 
					            for (const guildMember of guildMembers) {
 | 
				
			||||||
 | 
					                if (guildMember.accountId.equals(accountId)) {
 | 
				
			||||||
 | 
					                    missingEntry = false;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (missingEntry) {
 | 
				
			||||||
 | 
					                await GuildMember.insertOne({
 | 
				
			||||||
 | 
					                    accountId: accountId,
 | 
				
			||||||
 | 
					                    guildId: inventory.GuildId,
 | 
				
			||||||
 | 
					                    status: 0,
 | 
				
			||||||
 | 
					                    rank: 0
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            res.json({
 | 
					            res.json({
 | 
				
			||||||
                _id: toOid(guild._id),
 | 
					                _id: toOid(guild._id),
 | 
				
			||||||
                Name: guild.Name,
 | 
					                Name: guild.Name,
 | 
				
			||||||
 | 
				
			|||||||
@ -7,11 +7,14 @@ import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
 | 
				
			|||||||
import { PersonalRooms } from "@/src/models/personalRoomsModel";
 | 
					import { PersonalRooms } from "@/src/models/personalRoomsModel";
 | 
				
			||||||
import { Ship } from "@/src/models/shipModel";
 | 
					import { Ship } from "@/src/models/shipModel";
 | 
				
			||||||
import { Stats } from "@/src/models/statsModel";
 | 
					import { Stats } from "@/src/models/statsModel";
 | 
				
			||||||
 | 
					import { GuildMember } from "@/src/models/guildModel";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const deleteAccountController: RequestHandler = async (req, res) => {
 | 
					export const deleteAccountController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
 | 
					    // TODO: Handle the account being the creator of a guild
 | 
				
			||||||
    await Promise.all([
 | 
					    await Promise.all([
 | 
				
			||||||
        Account.deleteOne({ _id: accountId }),
 | 
					        Account.deleteOne({ _id: accountId }),
 | 
				
			||||||
 | 
					        GuildMember.deleteOne({ accountId: accountId }),
 | 
				
			||||||
        Inbox.deleteMany({ ownerId: accountId }),
 | 
					        Inbox.deleteMany({ ownerId: accountId }),
 | 
				
			||||||
        Inventory.deleteOne({ accountOwnerId: accountId }),
 | 
					        Inventory.deleteOne({ accountOwnerId: accountId }),
 | 
				
			||||||
        Loadout.deleteOne({ loadoutOwnerId: accountId }),
 | 
					        Loadout.deleteOne({ loadoutOwnerId: accountId }),
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,8 @@ import {
 | 
				
			|||||||
    ITechProjectDatabase,
 | 
					    ITechProjectDatabase,
 | 
				
			||||||
    ITechProjectClient,
 | 
					    ITechProjectClient,
 | 
				
			||||||
    IDojoDecoDatabase,
 | 
					    IDojoDecoDatabase,
 | 
				
			||||||
    ILongMOTD
 | 
					    ILongMOTD,
 | 
				
			||||||
 | 
					    IGuildMemberDatabase
 | 
				
			||||||
} from "@/src/types/guildTypes";
 | 
					} from "@/src/types/guildTypes";
 | 
				
			||||||
import { Document, Model, model, Schema, Types } from "mongoose";
 | 
					import { Document, Model, model, Schema, Types } from "mongoose";
 | 
				
			||||||
import { fusionTreasuresSchema, typeCountSchema } from "./inventoryModels/inventoryModel";
 | 
					import { fusionTreasuresSchema, typeCountSchema } from "./inventoryModels/inventoryModel";
 | 
				
			||||||
@ -113,3 +114,12 @@ export type TGuildDatabaseDocument = Document<unknown, {}, IGuildDatabase> &
 | 
				
			|||||||
        keyof GuildDocumentProps
 | 
					        keyof GuildDocumentProps
 | 
				
			||||||
    > &
 | 
					    > &
 | 
				
			||||||
    GuildDocumentProps;
 | 
					    GuildDocumentProps;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const guildMemberSchema = new Schema<IGuildMemberDatabase>({
 | 
				
			||||||
 | 
					    accountId: Types.ObjectId,
 | 
				
			||||||
 | 
					    guildId: Types.ObjectId,
 | 
				
			||||||
 | 
					    status: { type: Number, required: true },
 | 
				
			||||||
 | 
					    rank: { type: Number, default: 7 }
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const GuildMember = model<IGuildMemberDatabase>("GuildMember", guildMemberSchema);
 | 
				
			||||||
 | 
				
			|||||||
@ -35,6 +35,13 @@ export interface ILongMOTD {
 | 
				
			|||||||
    //authorGuildName: "";
 | 
					    //authorGuildName: "";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface IGuildMemberDatabase {
 | 
				
			||||||
 | 
					    accountId: Types.ObjectId;
 | 
				
			||||||
 | 
					    guildId: Types.ObjectId;
 | 
				
			||||||
 | 
					    status: number;
 | 
				
			||||||
 | 
					    rank: number;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IGuildVault {
 | 
					export interface IGuildVault {
 | 
				
			||||||
    DojoRefundRegularCredits?: number;
 | 
					    DojoRefundRegularCredits?: number;
 | 
				
			||||||
    DojoRefundMiscItems?: IMiscItem[];
 | 
					    DojoRefundMiscItems?: IMiscItem[];
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user