Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
description: '',
schema: {
type: 'string',
},
},
},
})
.build();
@api(apispec)
class MyController {
constructor(
@inject(AuthenticationBindings.CURRENT_USER) private user: UserProfile,
) {}
@authenticate(AUTH_STRATEGY_NAME)
async whoAmI(): Promise {
return this.user.id;
}
}
app.controller(MyController);
}
char.currentMana! = char.maxMana!;
char.attack! += 3 * levels;
char.defence! += levels;
await this.characterRepository!.updateById(currentUser.email, char);
return char;
}
@patch('/updatecharacter/initCharacter', {
responses: {
'200': {
description: 'initCharacter',
content: {},
},
},
})
@authenticate('jwt', {
required: [PermissionKey.ViewOwnUser, PermissionKey.UpdateOwnUser],
})
async initCharacter(@requestBody() newChar: NewChar): Promise {
const currentUser = await this.getCurrentUser();
//equip new weapon
let char: Character = await this.characterRepository.findById(
currentUser.email,
);
console.log(newChar);
char.attack! += newChar.gear.weapon.attack!;
char.defence! += newChar.gear.weapon.defence!;
char.attack! += newChar.gear.armor.attack!;
char.defence! += newChar.gear.armor.defence!;
char.name = newChar.name;
await this.characterRepository.updateById(currentUser.email, char);
//console.log(await this.characterRepository.findById(currentUser.email));
.create(weapon);
}
/**
* update armor for current character
* @param armor armor
*/
@patch('/updatecharacter/armor', {
responses: {
'200': {
description: 'update armor',
content: {'application/json': {schema: Armor}},
},
},
})
@authenticate('jwt', {
required: [PermissionKey.ViewOwnUser, PermissionKey.UpdateOwnUser],
})
async updateArmor(@requestBody() armor: Armor): Promise {
const currentUser = await this.getCurrentUser();
//equip new armor
let char: Character = await this.characterRepository.findById(
currentUser.email,
);
char.attack! += armor.attack;
char.defence! += armor.defence;
//unequip old armor
let filter: Filter = {where: {characterId: currentUser.email}};
if ((await this.armorRepository.find(filter))[0] != undefined) {
let oldArmor: Armor = await this.characterRepository
.armor(currentUser.email)
): Promise {
return await this.characterRepository.findById(email);
}
/**
* patch character by email
* @param where filter
*/
@patch('/admin/characters/{email}', {
responses: {
'204': {
description: 'Character PATCH success',
},
},
})
@authenticate('jwt', {"required": [PermissionKey.ViewAnyUser, PermissionKey.UpdateAnyUser]})
async updateById(
@param.query.string('email') email: string,
@requestBody() character: Character,
): Promise {
await this.characterRepository.updateById(email, character);
}
/**
* delete character by email
*/
@del('/admin/characters/{email}', {
responses: {
'204': {
description: 'Character DELETE success',
},
},
return this.userRepo.orders(userId).create(order);
}
@get('/users/{userId}/orders', {
responses: {
'200': {
description: "Array of User's Orders",
content: {
'application/json': {
schema: {type: 'array', items: {'x-ts-type': Order}},
},
},
},
},
})
@authenticate('jwt')
@authorize({resource: 'order', scopes: ['find'], voters: [compareId]})
async findOrders(
@param.path.string('userId') userId: string,
@param.query.string('filter') filter?: Filter,
): Promise {
const orders = await this.userRepo.orders(userId).find(filter);
return orders;
}
@patch('/users/{userId}/orders', {
responses: {
'200': {
description: 'User.Order PATCH success count',
content: {'application/json': {schema: CountSchema}},
},
},
@param.path.string('userId') userId: string,
@param.query.string('filter') filter?: Filter,
): Promise {
const orders = await this.userRepo.orders(userId).find(filter);
return orders;
}
@patch('/users/{userId}/orders', {
responses: {
'200': {
description: 'User.Order PATCH success count',
content: {'application/json': {schema: CountSchema}},
},
},
})
@authenticate('jwt')
@authorize({resource: 'order', scopes: ['patch'], voters: [compareId]})
async patchOrders(
@param.path.string('userId') userId: string,
@requestBody() order: Partial,
@param.query.string('where') where?: Where,
): Promise {
return this.userRepo.orders(userId).patch(order, where);
}
@del('/users/{userId}/orders', {
responses: {
'200': {
description: 'User.Order DELETE success count',
content: {'application/json': {schema: CountSchema}},
},
},
async printCurrentUser(): Promise {
return this.getCurrentUser();
}
/**
* show current character
*/
@patch('/characters/name', {
responses: {
'200': {
description: 'Character model instance',
content: {'application/json': {schema: {'x-ts-type': Character}}},
},
},
})
@authenticate('jwt', {required: [PermissionKey.ViewOwnUser]})
async changeName(@requestBody() newName: Partial): Promise {
const currentUser = await this.getCurrentUser();
let char: Character = await this.characterRepository.findById(
currentUser.email,
);
char.name = newName.name!;
return await this.characterRepository.updateById(currentUser.email, char);
}
/**
* show current character
*/
@get('/characters', {
responses: {
'200': {
description: 'Character model instance',
return await this.characterRepository.find(filter);
}
/**
* path all character
* @param where filter
*/
@patch('/admin/characters', {
responses: {
'200': {
description: 'Character PATCH success count',
content: {'application/json': {schema: CountSchema}},
},
},
})
@authenticate('jwt', {"required": [PermissionKey.ViewAnyUser, PermissionKey.UpdateAnyUser]})
async updateAll(
@requestBody() character: Character,
@param.query.object('where', getWhereSchemaFor(Character)) where?: Where,
): Promise {
return await this.characterRepository.updateAll(character, where);
}
/**
* show character by email
* @param email email
*/
@get('/admin/characters/{email}', {
responses: {
'200': {
description: 'Character model instance',
content: {'application/json': {schema: {'x-ts-type': Character}}},
@requestBody() character: Character,
): Promise {
await this.characterRepository.updateById(email, character);
}
/**
* delete character by email
*/
@del('/admin/characters/{email}', {
responses: {
'204': {
description: 'Character DELETE success',
},
},
})
@authenticate('jwt', {"required": [PermissionKey.ViewAnyUser, PermissionKey.DeleteAnyUser]})
async deleteById(
@param.path.string('email') email: string
): Promise {
//delete weapon, armor, and skill
await this.characterRepository.weapon(email).delete();
await this.characterRepository.armor(email).delete();
await this.characterRepository.skill(email).delete();
///
await this.characterRepository.deleteById(email);
}
}
async findById(): Promise {
const currentUser = await this.getCurrentUser();
return await this.characterRepository.findById(currentUser.email);
}
/**
* delete current character
*/
@del('/characters', {
responses: {
'204': {
description: 'Character DELETE success',
},
},
})
@authenticate('jwt', {required: [PermissionKey.DeleteOwnUser]})
async deleteById(): Promise {
const currentUser = await this.getCurrentUser();
//delete weapon, armor, and skill
await this.characterRepository.weapon(currentUser.email).delete();
await this.characterRepository.armor(currentUser.email).delete();
await this.characterRepository.skill(currentUser.email).delete();
///
await this.characterRepository.deleteById(currentUser.email);
}
}