Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private onPostInventoryCosmetics(req: express.Request, res: express.Response, next: express.NextFunction): void {
const reqUserId: number = Number(req.params.userId)
const reqCosmetics: InventoryCosmetics = req.body
LogInstance.info(`POST request to /users/${reqUserId}/inventory/cosmetics`)
// return bad request if the userid or the body are invalid
if (isNaN(reqUserId)
|| reqCosmetics.ctItem == null
|| reqCosmetics.terItem == null
|| reqCosmetics.headItem == null
|| reqCosmetics.gloveItem == null
|| reqCosmetics.backItem == null
|| reqCosmetics.stepsItem == null
|| reqCosmetics.cardItem == null
|| reqCosmetics.sprayItem == null) {
return res.status(400).end()
}
/*if (cant find user) {
return res.status(404).end()
private onGetInventory(req: express.Request, res: express.Response, next: express.NextFunction): void {
const reqUserId: number = Number(req.params.userId)
LogInstance.info(`GET request to /users/${reqUserId}/inventory`)
// return bad request if the userid is invalid
if (isNaN(reqUserId)) {
return res.status(400).end()
}
/*if (cant find user) {
return res.status(404).end()
}*/
const sampleResponse: InventoryItem[] = [
{
itemId: 100,
ammount: 3,
},
{
private onGetInventoryCosmetics(req: express.Request, res: express.Response, next: express.NextFunction): void {
const reqUserId: number = Number(req.params.userId)
LogInstance.info(`GET request to /users/${reqUserId}/inventory/cosmetics`)
// return bad request if the userid or the body are invalid
if (isNaN(reqUserId)) {
return res.status(400).end()
}
/*if (cant find user) {
return res.status(404).end()
}*/
const sampleResponse: InventoryCosmetics = {
ctItem: 1033,
terItem: 1034,
headItem: 10062,
gloveItem: 30018,
backItem: 20042,
private async setupDb(): Promise {
const dbUri: string = formatMongoUri(process.env.DB_HOST,
process.env.DB_PORT, process.env.DB_NAME)
// create a mongo connection
await mongoose.connect(dbUri, { useNewUrlParser: true, useUnifiedTopology: true })
LogInstance.info('Connected to ' + dbUri + ' db sucessfully')
// create global vars document
await UserVars.initialize()
}
private onDeleteInventory(req: express.Request, res: express.Response, next: express.NextFunction): void {
const reqUserId: number = Number(req.params.userId)
const reqItem: InventoryItem = req.body
LogInstance.info(`DELETE request to /users/${reqUserId}/inventory`)
// return bad request if the userid or the body are invalid
if (isNaN(reqUserId)
|| reqItem.itemId == null
|| reqItem.ammount == null) {
return res.status(400).end()
}
/*if (cant find user) {
return res.status(404).end()
}*/
// return OK
res.status(200).end()
}
private onGetInventoryLoadout(req: express.Request, res: express.Response, next: express.NextFunction): void {
const reqUserId: number = Number(req.params.userId)
const reqLoadoutNum: number = Number(req.body.loadoutNum)
LogInstance.info(`GET request to /users/${reqUserId}/inventory/loadout`)
// return bad request if the userid or the body are invalid
if (isNaN(reqUserId) || isNaN(reqLoadoutNum)) {
return res.status(400).end()
}
/*if (cant find user) {
return res.status(404).end()
}*/
const sampleResponse: InventoryLoadout = {
loadoutNum: reqLoadoutNum,
primary: 5218,
secondary: 5288,
melee: 84,
hegrenade: 4,
private onPostInventoryLoadout(req: express.Request, res: express.Response, next: express.NextFunction): void {
const reqUserId: number = Number(req.params.userId)
const reqLoadout: InventoryLoadout = req.body
LogInstance.info(`POST request to /users/${reqUserId}/inventory/loadout`)
// return bad request if the userid or the body are invalid
if (isNaN(reqUserId)
|| reqLoadout.loadoutNum == null
|| reqLoadout.primary == null
|| reqLoadout.secondary == null
|| reqLoadout.melee == null
|| reqLoadout.hegrenade == null
|| reqLoadout.flash == null
|| reqLoadout.smoke == null) {
return res.status(400).end()
}
/*if (cant find user) {
return res.status(404).end()
}*/
private onPostInventoryBuyMenu(req: express.Request, res: express.Response, next: express.NextFunction): void {
const reqUserId: number = Number(req.params.userId)
const reqLoadout: InventorySubBuyMenu = req.body
LogInstance.info(`POST request to /users/${reqUserId}/inventory/loadout`)
// return bad request if the userid or the body are invalid
if (isNaN(reqUserId)
|| reqLoadout.index == null
|| reqLoadout.weapons == null) {
return res.status(400).end()
}
/*if (cant find user) {
return res.status(404).end()
}*/
// return OK
res.status(200).end()
}
}
public async listen(): Promise {
await this.setupDb()
this.server = this.app.listen(this.app.get('port'))
LogInstance.info('Started user service')
LogInstance.info('Listening at ' + this.app.get('port'))
}
public async listen(): Promise {
await this.setupDb()
this.server = this.app.listen(this.app.get('port'))
LogInstance.info('Started user service')
LogInstance.info('Listening at ' + this.app.get('port'))
}