forked from OpenWF/SpaceNinjaServer
		
	Reviewed-on: OpenWF/SpaceNinjaServer#2694 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
		
			
				
	
	
		
			22 lines
		
	
	
		
			815 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			815 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import type { RequestHandler } from "express";
 | 
						|
import { getAccountIdForRequest } from "../../services/loginService.ts";
 | 
						|
import { addFusionPoints, getInventory } from "../../services/inventoryService.ts";
 | 
						|
 | 
						|
export const addCurrencyController: RequestHandler = async (req, res) => {
 | 
						|
    const accountId = await getAccountIdForRequest(req);
 | 
						|
    const request = req.body as IAddCurrencyRequest;
 | 
						|
    const inventory = await getInventory(accountId, request.currency);
 | 
						|
    if (request.currency == "FusionPoints") {
 | 
						|
        addFusionPoints(inventory, request.delta);
 | 
						|
    } else {
 | 
						|
        inventory[request.currency] += request.delta;
 | 
						|
    }
 | 
						|
    await inventory.save();
 | 
						|
    res.end();
 | 
						|
};
 | 
						|
 | 
						|
interface IAddCurrencyRequest {
 | 
						|
    currency: "RegularCredits" | "PremiumCredits" | "FusionPoints" | "PrimeTokens";
 | 
						|
    delta: number;
 | 
						|
}
 |