Skip to content

Commit

Permalink
Merge pull request #51 from Shahidul1004/fix-invalid-types-for-groupB…
Browse files Browse the repository at this point in the history
…y-function

Fix invalid types for the "groupBy" function
  • Loading branch information
omar-dulaimi authored Dec 31, 2022
2 parents e1ac49d + 84bac9a commit 2ad5cc9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@prisma/internals": "^4.8.0",
"pluralize": "^8.0.0",
"prisma-trpc-shield-generator": "0.0.0-rc.4",
"prisma-zod-generator": "^0.8.8",
"prisma-zod-generator": "^0.8.9",
"ts-morph": "^17.0.1",
"tslib": "^2.4.1"
},
Expand All @@ -40,7 +40,7 @@
"@types/node": "^18.11.18",
"@types/pluralize": "^0.0.29",
"prisma": "^4.8.0",
"trpc-shield": "^0.2.1",
"trpc-shield": "^0.3.0",
"typescript": "^4.9.4",
"zod": "^3.20.2"
},
Expand Down
26 changes: 18 additions & 8 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,19 @@ export function generateBaseRouter(
) {
const outputDir = parseEnvValue(options.generator.output as EnvValue);
sourceFile.addStatements(/* ts */ `
import { Context } from '${getRelativePath(outputDir, config.contextPath, options.schemaPath)}';
import { Context } from '${getRelativePath(
outputDir,
config.contextPath,
options.schemaPath,
)}';
`);

if (config.trpcOptionsPath) {
sourceFile.addStatements(/* ts */ `
import trpcOptions from '${getRelativePath(
outputDir,
config.trpcOptionsPath,
options.schemaPath
options.schemaPath,
)}';
`);
}
Expand Down Expand Up @@ -143,14 +147,20 @@ export function generateProcedure(
baseOpType: string,
config: Config,
) {
let input = 'input';
const nameWithoutModel = name.replace(modelName as string, '');
if (nameWithoutModel === 'groupBy') {
input =
'{ where: input.where, orderBy: input.orderBy, by: input.by, having: input.having, take: input.take, skip: input.skip }';
}
sourceFile.addStatements(/* ts */ `${name}: ${getProcedureName(config)}
.input(${typeName})
.${getProcedureTypeByOpName(baseOpType)}(async ({ ctx, input }) => {
const ${name} = await ctx.prisma.${uncapitalizeFirstLetter(
.input(${typeName})
.${getProcedureTypeByOpName(baseOpType)}(async ({ ctx, input }) => {
const ${name} = await ctx.prisma.${uncapitalizeFirstLetter(
modelName,
)}.${opType.replace('One', '')}(input);
return ${name};
}),`);
)}.${opType.replace('One', '')}(${input});
return ${name};
}),`);
}

export function generateRouterSchemaImports(
Expand Down

0 comments on commit 2ad5cc9

Please sign in to comment.