Skip to content

Commit

Permalink
Merge pull request #23 from Callgent/user-as-a-service
Browse files Browse the repository at this point in the history
User as a service
  • Loading branch information
Jamesp918 authored May 29, 2024
2 parents af83e70 + a61658d commit 35db1de
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "prisma generate",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
Expand All @@ -24,6 +25,7 @@
"prisma:generate": "npx prisma generate",
"prisma:studio": "npx prisma studio",
"prisma:seed": "npx prisma db seed",
"prisma:seed:test": "SEED_TEST_DATA=1 npx prisma db seed",
"prepare": "husky",
"commit": "git-cz",
"release": "standard-version"
Expand Down
9 changes: 6 additions & 3 deletions src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@ function registerApi(
},
},
});

logger.log(
`API Documentation: http://localhost:${
process.env.PORT || 3000
}/docs/api`,
);
}
logger.log(
`API Documentation: http://localhost:${process.env.PORT || 3000}/docs/api`,
);

return { defaultApiVersion, devDocVersion };
}
Expand Down
11 changes: 9 additions & 2 deletions src/callgent-functions/callgent-functions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,21 @@ export class CallgentApis extends ApiSpec {
}

export class CallgentApiText {
@ApiProperty({
required: true,
description: 'The callgent server-endpoint uuid',
})
@IsNotEmpty()
@EntityIdExists('endpoint', 'uuid')
endpoint: string;

@ApiProperty({
required: true,
description: 'The api content text to parse',
})
@IsNotEmpty()
text: string;

@ApiProperty({
required: false,
description: 'The format of the api content text',
Expand All @@ -67,7 +74,7 @@ export class CallgentFunctionsController {
@ApiOperation({
summary:
'Create batch of new CallgentFunction. Exception if existing one with same name in the same callgent',
description: 'return { data: count } on success',
description: 'return { data: imported_functions_count } on success',
})
@Post()
async createBatch(
Expand All @@ -87,7 +94,7 @@ export class CallgentFunctionsController {

@ApiOperation({
summary: 'Parse import text and create batch.',
description: 'return { data: count } on success',
description: 'return { data: imported_functions_count } on success',
})
@Post('import')
async importBatch(
Expand Down
22 changes: 12 additions & 10 deletions src/callgent-functions/callgent-functions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TransactionHost, Transactional } from '@nestjs-cls/transactional';
import { TransactionalAdapterPrisma } from '@nestjs-cls/transactional-adapter-prisma';
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
import { PaginatorTypes, paginator } from '@nodeteam/nestjs-prisma-pagination';
import { CallgentFunction, Prisma, PrismaClient } from '@prisma/client';
import { Prisma, PrismaClient } from '@prisma/client';
import { ApiSpec } from '../endpoints/adaptors/endpoint-adaptor.interface';
import { EndpointDto } from '../endpoints/dto/endpoint.dto';
import { EndpointsService } from '../endpoints/endpoints.service';
Expand Down Expand Up @@ -88,15 +88,17 @@ export class CallgentFunctionsService {

const { apis } = spec;
// validation
const actMap = apis.map<Prisma.CallgentFunctionUncheckedCreateInput>((e) => {
return {
...e,
uuid: Utils.uuid(),
endpointUuid: endpoint.uuid,
callgentUuid: endpoint.callgentUuid,
createdBy: createdBy,
};
});
const actMap = apis.map<Prisma.CallgentFunctionUncheckedCreateInput>(
(e) => {
return {
...e,
uuid: Utils.uuid(),
endpointUuid: endpoint.uuid,
callgentUuid: endpoint.callgentUuid,
createdBy: createdBy,
};
},
);

const prisma = this.txHost.tx as PrismaClient;
const { count: actionsCount } = await prisma.callgentFunction.createMany({
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/listeners/callgent-created.listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class CallgentCreatedListener {
createdBy: callgent.createdBy,
})
.then((endpoint) => {
// no await init, it may be slow
// no await init, it may be slow, TODO: tx invalid
this.endpointsService.init(endpoint.uuid, []);
return endpoint;
}),
Expand Down

0 comments on commit 35db1de

Please sign in to comment.