Skip to content

Instantly share code, notes, and snippets.

@GoodnessEzeokafor
Created September 15, 2024 13:08
Show Gist options
  • Save GoodnessEzeokafor/4797116f108e9bdd9ffcc61eebc26008 to your computer and use it in GitHub Desktop.
Save GoodnessEzeokafor/4797116f108e9bdd9ffcc61eebc26008 to your computer and use it in GitHub Desktop.
import { Injectable, OnApplicationShutdown } from '@nestjs/common';
import { FeedbackFactoryServices } from './feedback-factory.service';
import { DataSource } from 'typeorm';
import { IDatabaseServices } from 'src/core';
@Injectable()
export class FeedbackServices implements OnApplicationShutdown {
constructor(
private readonly data: IDatabaseServices,
private readonly factory: FeedbackFactoryServices,
private readonly connection: DataSource,
) {}
async onApplicationShutdown(signal: string) {
console.log('signal', signal);
this.connection.destroy();
}
async sendFeedback(payload: any) {
const factory = this.factory.create(payload);
return await this.data.feedbacks.create(factory);
}
async getFeedbacks() {
return await this.data.feedbacks.findAllWithPagination({});
}
async getSingleFeedback() {
return await this.data.feedbacks.findOne({ email: '[email protected]' });
}
async deleteFeedback() {
return await this.data.feedbacks.delete({ email: '[email protected]' });
}
async updateFeedback() {
return await this.data.feedbacks.update(
{ email: '[email protected]' },
{ email: '[email protected]' },
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment