添加 src/controllers/api/createGuildDojoController.ts
This commit is contained in:
		
							parent
							
								
									4ea2f59947
								
							
						
					
					
						commit
						4a80d37b09
					
				
							
								
								
									
										41
									
								
								src/controllers/api/createGuildDojoController.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/controllers/api/createGuildDojoController.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
				
			||||||
 | 
					import { getDojoClient, getGuildForRequest, getGuildLogForRequest } from "@/src/services/guildService";
 | 
				
			||||||
 | 
					import { IOid } from "@/src/types/commonTypes";
 | 
				
			||||||
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
 | 
					import { Types } from "mongoose";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// eslint-disable-next-line @typescript-eslint/no-misused-promises
 | 
				
			||||||
 | 
					export const createGuildDojoController: RequestHandler = async (req, res) => {
 | 
				
			||||||
 | 
					    const guild = await getGuildForRequest(req);
 | 
				
			||||||
 | 
					    const guildLog = await getGuildLogForRequest(req);
 | 
				
			||||||
 | 
					    const payload = getJSONfromString(String(req.body)) as ICreateGuildDojoRequest;
 | 
				
			||||||
 | 
					    // Populate dojo info if not present
 | 
				
			||||||
 | 
					    var componentId = new Types.ObjectId();
 | 
				
			||||||
 | 
					    if (!guild.DojoComponents || guild.DojoComponents.length == 0) {
 | 
				
			||||||
 | 
					        guild.DojoComponents?.push({
 | 
				
			||||||
 | 
					            _id: componentId,
 | 
				
			||||||
 | 
					            pf: payload.SpawnComponent.pf,
 | 
				
			||||||
 | 
					            ppf: "",
 | 
				
			||||||
 | 
					            CompletionTime: new Date(Date.now()),
 | 
				
			||||||
 | 
					            DecoCapacity: 600
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        await guild.save();
 | 
				
			||||||
 | 
					        guildLog.RoomChanges.push({
 | 
				
			||||||
 | 
					            dateTime: new Date(Date.now()),
 | 
				
			||||||
 | 
					            entryType: 1,
 | 
				
			||||||
 | 
					            details: payload.SpawnComponent.pf
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        await guildLog.save();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    res.json(await getDojoClient(guild, 0, componentId));
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface ICreateGuildDojoRequest {
 | 
				
			||||||
 | 
					    SpawnComponent: ICreateGuildDojoSpawnComponent;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface ICreateGuildDojoSpawnComponent {
 | 
				
			||||||
 | 
					    id: IOid;
 | 
				
			||||||
 | 
					    pf: string;
 | 
				
			||||||
 | 
					    ppf: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user