Skip to content

Commit

Permalink
fix custom definition count invariant
Browse files Browse the repository at this point in the history
  • Loading branch information
RusovDmitriy committed Sep 4, 2020
1 parent 0ab906c commit 473f2fd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/configuration/src/services/CustomDefinitionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class {
const { data } = call.request

await this.testResourceExistsInvariant(data.resourceId)
const index = await this.getNextIndex(data.type)
const index = await this.getNextIndex(data.resourceId, data.type)

const instance = CustomDefinition.create({
...call.request.data,
Expand All @@ -101,11 +101,14 @@ export default class {
}
}

private async getNextIndex(type: custom_definition.CustomDefinitionType): Promise<number> {
private async getNextIndex(resourceId: string, type: custom_definition.CustomDefinitionType): Promise<number> {
const INDEX_LIMIT = 200

const [customDefinition] = await this.customDefinitionRepository.findAll({
filter: { type },
filter: {
resourceId,
type
},
limit: 1,
orderBy: 'index:desc'
})
Expand Down

0 comments on commit 473f2fd

Please sign in to comment.