From 9ebcf0c735cbb2d26187327a2c49077fa9b1c01a Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Thu, 6 Jun 2024 07:44:21 -0400 Subject: [PATCH] snippet templates work with endpoint id overrides --- .../fdr/src/db/snippets/SnippetTemplate.ts | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/servers/fdr/src/db/snippets/SnippetTemplate.ts b/servers/fdr/src/db/snippets/SnippetTemplate.ts index af9d3d66dd..8651c120b7 100644 --- a/servers/fdr/src/db/snippets/SnippetTemplate.ts +++ b/servers/fdr/src/db/snippets/SnippetTemplate.ts @@ -156,23 +156,36 @@ export class SnippetTemplateDaoImpl implements SnippetTemplateDao { }): Promise { 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: {