Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
filter?: Filter,
): Promise {
return this.repository.findById(id, filter);
}
@get('/count', {
...response(200, `${modelName} count`, {schema: CountSchema}),
})
async count(
@param.query.object('where', getWhereSchemaFor(modelCtor))
where?: Where,
): Promise {
return this.repository.count(where);
}
@patch('/', {
...response(200, `Count of ${modelName} models updated`, {
schema: CountSchema,
}),
})
async updateAll(
@body(modelCtor, {partial: true}) data: Partial,
@param.query.object('where', getWhereSchemaFor(modelCtor))
where?: Where,
): Promise {
return this.repository.updateAll(
// FIXME(bajtos) Improve repository API to support this use case
// with no explicit type-casts required
data as DataObject,
where,
);
}
}),
})
async updateAll(
@body(modelCtor, {partial: true}) data: Partial,
@param.query.object('where', getWhereSchemaFor(modelCtor))
where?: Where,
): Promise {
return this.repository.updateAll(
// FIXME(bajtos) Improve repository API to support this use case
// with no explicit type-casts required
data as DataObject,
where,
);
}
@patch('/{id}', {
responses: {
'204': {description: `${modelName} was updated`},
},
})
async updateById(
@param(idPathParam) id: IdType,
@body(modelCtor, {partial: true}) data: Partial,
): Promise {
await this.repository.updateById(
id,
// FIXME(bajtos) Improve repository API to support this use case
// with no explicit type-casts required
data as DataObject,
);
}
content: {
'application/json': {
schema: {type: 'array', items: getModelSchemaRef(Note)},
},
},
},
},
})
async find(
@param.query.object('filter', getFilterSchemaFor(Note))
filter?: Filter,
): Promise {
return this.noteRepository.find(filter);
}
@patch('/notes', {
responses: {
'200': {
description: 'Note PATCH success count',
content: {'application/json': {schema: CountSchema}},
},
},
})
async updateAll(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Note, {partial: true}),
},
},
})
note: Partial,
type: 'array',
items: getModelSchemaRef(TodoList, {includeRelations: true}),
},
},
},
},
},
})
async find(
@param.query.object('filter', getFilterSchemaFor(TodoList))
filter?: Filter,
): Promise {
return this.todoListRepository.find(filter);
}
@patch('/todo-lists', {
responses: {
'200': {
description: 'TodoList PATCH success count',
content: {'application/json': {schema: CountSchema}},
},
},
})
async updateAll(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(TodoList, {partial: true}),
},
},
})
todoList: Partial,
levels++;
char.currentExp! -= char.nextLevelExp!;
char.nextLevelExp! += 100;
}
char.level! += levels;
char.maxHealth! += 10 * levels;
char.currentHealth! = char.maxHealth!;
char.maxMana! += 5 * levels;
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,
);
content: {'application/json': {schema: {'x-ts-type': Character}}},
},
},
})
@authenticate('jwt', {"required":[PermissionKey.ViewAnyUser]})
async findById(
@param.path.string('email') email: string
): 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
schema: {type: 'array', items: {'x-ts-type': Tenant}},
},
},
},
},
})
async find(
@param.query.object('filter', getFilterSchemaFor(Tenant))
filter?: Filter,
): Promise {
return await this.tenantRepository.find(filter);
}
@authenticate(STRATEGY.BEARER)
@authorize([PermissionKey.UpdateTenant])
@patch('/tenants', {
responses: {
'200': {
description: 'Tenant PATCH success count',
content: {'application/json': {schema: CountSchema}},
},
},
})
async updateAll(
@requestBody() tenant: Tenant,
@param.query.object('where', getWhereSchemaFor(Tenant))
where?: Where,
): Promise {
return await this.tenantRepository.updateAll(tenant, where);
}
@authenticate(STRATEGY.BEARER)
.weapon(currentUser.email)
.create(newChar.gear.weapon);
await this.characterRepository
.armor(currentUser.email)
.create(newChar.gear.armor);
await this.characterRepository
.skill(currentUser.email)
.create(newChar.gear.skill);
return newChar;
}
/**
* update weapon for current character
* @param weapon weapon
*/
@patch('/updatecharacter/weapon', {
responses: {
'200': {
description: 'update weapon',
content: {'application/json': {schema: Weapon}},
},
},
})
@authenticate('jwt', {
required: [PermissionKey.ViewOwnUser, PermissionKey.UpdateOwnUser],
})
async updateWeapon(@requestBody() weapon: Weapon): Promise {
const currentUser = await this.getCurrentUser();
//equip new weapon
let char: Character = await this.characterRepository.findById(
currentUser.email,
);
.get();
char.attack! -= oldArmor.attack;
char.defence! -= oldArmor.defence;
await this.characterRepository.armor(currentUser.email).delete();
}
await this.characterRepository.updateById(currentUser.email, char);
return await this.characterRepository
.armor(currentUser.email)
.create(armor);
}
/**
* update skill for current character
* @param skill skill
*/
@patch('/updatecharacter/skill', {
responses: {
'200': {
description: 'update skill',
content: {'application/json': {schema: Skill}},
},
},
})
@authenticate('jwt', {
required: [PermissionKey.ViewOwnUser, PermissionKey.UpdateOwnUser],
})
async updateSkill(@requestBody() skill: Skill): Promise {
const currentUser = await this.getCurrentUser();
await this.characterRepository.skill(currentUser.email).delete();
return await this.characterRepository
.skill(currentUser.email)
.create(skill);
},
})
async find(
@param.query.object('filter', getFilterSchemaFor(User))
filter?: Filter,
): Promise {
return await this.userRepository.find(filter);
}
@authenticate(STRATEGY.BEARER)
@authorize([
PermissionKey.UpdateAnyUser,
PermissionKey.UpdateOwnUser,
PermissionKey.UpdateTenantUser,
])
@patch('/users', {
responses: {
'200': {
description: 'User PATCH success count',
content: {'application/json': {schema: CountSchema}},
},
},
})
async updateAll(
@requestBody() user: User,
@param.query.object('where', getWhereSchemaFor(User)) where?: Where,
): Promise {
return await this.userRepository.updateAll(user, where);
}
@authenticate(STRATEGY.BEARER)
@authorize([