Service API for circle server applications.
$ git clone https://github.com/circle/circle.gitrename the .env.sample to .env
$ npm install# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov$ nest g module <module-name>Run
$ nest g helpto see all schema generation options
Each project uses Prisma
Edit the prisma/schema.prisma to update database schema
Run
$ npx prisma migrate dev to sync schema file with the database
$ npx prisma migrate init to initialize database schema
$ npx prisma db seed to seed the db. Make sure to add
"prisma": {
"seed": "npx ts-node prisma/seed.ts"
}to package.json and create a seed.ts file in the prisma directory
Example seed file
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function seed() {
await prisma.user.create({
data: {
email: 'johndoe@example.com',
username: 'johndoe'
}
})
}
seed()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);Change the queue: '' to the name of the service e.g queue: 'template-service'
In the module for the service or controller that requires connecting to other microservices. Add
ClientsModule.register([
{
name: <CLIENT_NAME>,
options: {
urls: config.rmq.urls,
queue: <MICROSERVICE_QUEUE_NAME>, // USERDATA_QUEUE
persistent: true,
},
},
])Then in the service or controller controller. Add @Inject(<CLIENT_NAME>) private nameClient: ClientProxy
To make API calls to 3rd party platforms, the project uses @nestjs/axios which returns response as an Observable,
use rxjs's lastValueFrom to get the resulting data when using Promise
Import the nestjs http module in the module and import the http service to your controller/service
imports: [HttpModule]
private http: HttpService
Check @nestjs/axios for more details
Example
const response = await lastValueFrom(this.http.get('http://localhost:3000/))