2025-01-24 14:13:21 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { RequestHandler } from "express";
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-19 14:09:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { parseString } from "@/src/helpers/general";
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-24 14:13:21 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { getJSONfromString } from "@/src/helpers/stringHelpers";
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-19 14:09:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { getInventory } from "@/src/services/inventoryService";
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-31 17:24:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { IGroup } from "@/src/types/loginTypes";
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-19 14:09:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { giveKeyChainItem } from "@/src/services/questService";
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-24 14:13:21 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								export const giveKeyChainTriggeredItemsController: RequestHandler = async (req, res) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const accountId = parseString(req.query.accountId);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-31 17:24:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const keyChainInfo = getJSONfromString<IKeyChainRequest>((req.body as string).toString());
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-24 14:13:21 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const inventory = await getInventory(accountId);
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-21 15:46:09 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const inventoryChanges = await giveKeyChainItem(inventory, keyChainInfo);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-24 14:13:21 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    await inventory.save();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-19 14:09:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    res.send(inventoryChanges);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-24 14:13:21 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-31 17:24:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								export interface IKeyChainRequest {
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-24 14:13:21 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    KeyChain: string;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ChainStage: number;
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-31 17:24:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Groups?: IGroup[];
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-24 14:13:21 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |