Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made lookup by nameID to be separate to lookup by UUID #4580

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed this, creating another PR

},
});
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;
}
ccanos marked this conversation as resolved.
Show resolved Hide resolved

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