knack-nest
v0.0.7
Published
A knack library for nestjs
Downloads
1
Readme
Knack-nest is a typescript library for integrate knack api on Nestjs applications.
Installation
Use the package manager npm, yarn to install knack-nest.
npm i knack-nest
or
yarn add knack-nest
Usage
app.module.ts
@Module({
imports: [
KnackModule.forRoot({
appId: 'knack-app-id',
apiKey: 'kncak-api-key',
host: 'optional-host',
}),
ExampleModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
example.entity.ts
import { KnackObject } from 'knack-nest';
@KnackObject('object_1')
export class Example {
objectKey: string;
...
}
example.module.ts
import { Module } from '@nestjs/common';
import { ExampleService } from './example.service';
import { ExampleController } from './example.controller';
import { KnackModule } from 'knack-nest';
import { Example } from './entities/example.entity';
@Module({
controllers: [ExampleController],
providers: [ExampleService],
imports: [KnackModule.forFeature([Example])],
})
export class ExampleModule {}
example.service.ts
import { Injectable } from '@nestjs/common';
import { InjectObjectRepository, KnackRepository } from 'knack-nest';
import { Example } from './entities/example.entity';
import { CreateExampleDto } from './dto/create-example.dto';
import { UpdateExampleDto } from './dto/update-example.dto';
@Injectable()
export class ExampleService {
constructor(
@InjectObjectRepository(Example)
private readonly exampleHandler: KnackRepository<Example>,
) {}
async findAll() {
const examples = await this.exampleHandler.getRecords({});
return examples;
}
async create(createExampleDto: CreateExampleDto) {
const example = await this.exampleHandler.createRecord(createExampleDto);
return example;
}
async update(updateExampleDto: UpdateExampleDto) {
const example = await this.exampleHandler.updateRecord(updateExampleDto);
return example;
}
async delete(recordId: string) {
const result = await this.exampleHandler.deleteRecord({ recordId });
return result;
}
}
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.