Skip to content

Commit

Permalink
Merge pull request #4580 from alkem-io/client-6293
Browse files Browse the repository at this point in the history
made lookup by nameID to be separate to lookup by UUID
  • Loading branch information
ccanos authored Oct 3, 2024
2 parents 3bf99f4 + 488e939 commit a382fc7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
21 changes: 6 additions & 15 deletions src/domain/template/template/template.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,31 +380,22 @@ export class TemplateService {
});
}

async getTemplateInTemplatesSetOrFail(
async getTemplateByNameIDInTemplatesSetOrFail(
templatesSetID: string,
templateIdOrNameId: string
templateNameId: string
): Promise<ITemplate> {
let template = await this.templateRepository.findOne({
const template = await this.templateRepository.findOne({
where: {
templatesSet: {
id: templatesSetID,
},
nameID: templateIdOrNameId,
id: templateNameId,
},
});
if (!template) {
template = await this.templateRepository.findOne({
where: {
templatesSet: {
id: templatesSetID,
},
id: templateIdOrNameId,
},
});
}

if (!template) {
throw new EntityNotFoundException(
`Templates with ID/NameId(${templatesSetID}) not found!`,
`Templates with NameID (${templateNameId}) not found in templatesSet with ID: ${templatesSetID}!`,
LogContext.TEMPLATES
);
}
Expand Down
37 changes: 22 additions & 15 deletions src/library/innovation-pack/innovaton.pack.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { UUID_LENGTH } from '@common/constants';
import { LogContext, ProfileType } from '@common/enums';
import {
EntityNotFoundException,
Expand Down Expand Up @@ -148,20 +147,11 @@ export class InnovationPackService {
innovationPackID: string,
options?: FindOneOptions<InnovationPack>
): Promise<IInnovationPack | never> {
let innovationPack: IInnovationPack | null = null;
if (innovationPackID.length === UUID_LENGTH) {
innovationPack = await this.innovationPackRepository.findOne({
where: { id: innovationPackID },
...options,
});
}
if (!innovationPack) {
// look up based on nameID
innovationPack = await this.innovationPackRepository.findOne({
where: { nameID: innovationPackID },
...options,
});
}
const innovationPack = await this.innovationPackRepository.findOne({
where: { id: innovationPackID },
...options,
});

if (!innovationPack)
throw new EntityNotFoundException(
`Unable to find InnovationPack with ID: ${innovationPackID}`,
Expand All @@ -170,6 +160,23 @@ export class InnovationPackService {
return innovationPack;
}

async getInnovationPackByNameIdOrFail(
innovationPackNameID: string,
options?: FindOneOptions<InnovationPack>
): Promise<IInnovationPack | never> {
const innovationPack = await this.innovationPackRepository.findOne({
where: { nameID: innovationPackNameID },
...options,
});

if (!innovationPack)
throw new EntityNotFoundException(
`Unable to find InnovationPack using NameID: ${innovationPackNameID}`,
LogContext.LIBRARY
);
return innovationPack;
}

public async getProfile(
innovationPackInput: IInnovationPack,
relations?: FindOptionsRelations<IInnovationPack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class LookupByNameResolverFields {
@Args('NAMEID', { type: () => NameID }) nameid: string
): Promise<IInnovationPack> {
const innovationPack =
await this.innovationPackService.getInnovationPackOrFail(nameid);
await this.innovationPackService.getInnovationPackByNameIdOrFail(nameid);
this.authorizationService.grantAccessOrFail(
agentInfo,
innovationPack.authorization,
Expand All @@ -46,23 +46,24 @@ export class LookupByNameResolverFields {
@ResolveField(() => ITemplate, {
nullable: true,
description:
'Lookup the specified Template using a templatesSetId and NameID',
'Lookup the specified Template using a templatesSetId and the template NameID',
})
async template(
@CurrentUser() agentInfo: AgentInfo,
@Args('templatesSetID', { type: () => UUID }) ID: string,
@Args('NAMEID', { type: () => NameID }) nameID: string
): Promise<ITemplate> {
const template = await this.templateService.getTemplateInTemplatesSetOrFail(
ID,
nameID
);
const template =
await this.templateService.getTemplateByNameIDInTemplatesSetOrFail(
ID,
nameID
);

this.authorizationService.grantAccessOrFail(
agentInfo,
template.authorization,
AuthorizationPrivilege.READ,
`lookup InnovationPack by NameID: ${template.id}`
`lookup template by NameID: ${template.id}`
);

return template;
Expand Down

0 comments on commit a382fc7

Please sign in to comment.