Skip to content

Commit

Permalink
snippet templates work with endpoint id overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Jun 6, 2024
1 parent 2e46758 commit 9ebcf0c
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions servers/fdr/src/db/snippets/SnippetTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,36 @@ export class SnippetTemplateDaoImpl implements SnippetTemplateDao {
}): Promise<EndpointSnippetTemplate | null> {
const sdkFromRequest = await getSdkFromSdkRequest(this.prisma, loadSnippetTemplateRequest.sdk);

const snippetTemplate = await this.prisma.snippetTemplate.findFirst({
where: {
orgId: loadSnippetTemplateRequest.orgId,
apiName: loadSnippetTemplateRequest.apiId,
endpointPath: loadSnippetTemplateRequest.endpointId?.path,
endpointMethod: loadSnippetTemplateRequest.endpointId?.method,
sdkId: this.getSdkId(sdkFromRequest),
},
});
let snippetTemplate;
if (loadSnippetTemplateRequest.endpointId.identifierOverride != null) {
snippetTemplate = await this.prisma.snippetTemplate.findFirst({
where: {
orgId: loadSnippetTemplateRequest.orgId,
apiName: loadSnippetTemplateRequest.apiId,
identifierOverride: loadSnippetTemplateRequest.endpointId.identifierOverride,
sdkId: this.getSdkId(sdkFromRequest),
},
});
} else {
snippetTemplate = await this.prisma.snippetTemplate.findFirst({
where: {
orgId: loadSnippetTemplateRequest.orgId,
apiName: loadSnippetTemplateRequest.apiId,
endpointPath: loadSnippetTemplateRequest.endpointId?.path,
endpointMethod: loadSnippetTemplateRequest.endpointId?.method,
sdkId: this.getSdkId(sdkFromRequest),
},
});
}

if (!snippetTemplate) {
return null;
}
return {
endpointId: {
path: snippetTemplate.endpointPath,
path: snippetTemplate.apiDefinitionId,
method: snippetTemplate.endpointMethod,
identifierOverride: snippetTemplate.identifierOverride ?? undefined,
},
sdk: sdkFromRequest,
snippetTemplate: {
Expand Down

0 comments on commit 9ebcf0c

Please sign in to comment.