Skip to content

Instantly share code, notes, and snippets.

View GoodnessEzeokafor's full-sized avatar
🏠
Working from home

Ezeokafor GoodnessEzeokafor

🏠
Working from home
View GitHub Profile
@GoodnessEzeokafor
GoodnessEzeokafor / factory.ts
Created November 13, 2024 11:46
Refactoring my transaction factory service
@Injectable()
export class TransactionFactoryServices {
constructor(public readonly dbUtils: DatabaseUtilsService) {}
private mapProperty(source: any, target: any, propertyName: string): void {
if (source[propertyName]) {
target[propertyName] = source[propertyName];
}
}
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,
@GoodnessEzeokafor
GoodnessEzeokafor / abstraction.ts
Created September 15, 2024 13:07
clean-code architecture
/** generic repository */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Model } from 'sequelize';
import { IGenericRepository } from 'src/core';
export class SequelizeGenericRepository<T extends Model>
implements IGenericRepository<T>
{
private model: any;
/**
* gets the userId
* creates a redis key(identifier)
* checks if the key exists
* returns the data instead
*/
const redisKey = `transactions-v3-${userId}-${JSON.stringify(payload)}`;
const redisValue = await this.cache.get(redisKey);
if (redisValue) {
const { data, pagination } =
await this.data.transactions.findAllWithPagination(
{
...filterQuery,
isRevenue: false,
reconTransactionType: Not(In(excludedTransactionType)),
},
{
relationFields: ['user'],
selectFields: this.selectFields,
@GoodnessEzeokafor
GoodnessEzeokafor / db-select.ts
Created September 15, 2024 10:32
Select technique
const selectFields = [
'id',
'currency',
'currencyType',
'amount',
'type',
'reference',
'description',
'status',
// Use @UploadedFile() when uploading a single file/video/image
@Post('/upload-file')
@UseInterceptors(FileInterceptor('video'))
async createCheckedIn(
@UploadedFile() file: Express.Multer.File,
@Res() res: Response,
) {}
// use @UploadedFiles() when uploading multiple file/video/images
<html>
<head>
<script src="https://cdn.socket.io/4.3.2/socket.io.min.js"
integrity="sha384-KAZ4DtjNhLChOB/hxXuKqhMLYvx3b5MlT55xPEiNmREKRzeEm+RVPlTnAn0ajQNs"
crossorigin="anonymous"></script>
<script>
const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijc3YTJhMzdhLTA2ZDMtNGUwZC05OTVlLWMyZDI0YTZhZGVjMSIsInR5cGUiOiJhdXRoIiwiaWF0IjoxNzIzMDYyMDgxLCJleHAiOjE3MjMxNDg0ODF9.F19lekTdIeumR8uVlQeuJdXjAL81Ye5G_FCWRyU335U"
const socket = io('http://localhost:2242', {
query: { token }
@GoodnessEzeokafor
GoodnessEzeokafor / nigerian-banks.json
Created August 20, 2024 22:12 — forked from 03balogun/nigerian-banks.json
JSON List of Nigerian Banks and Codes
{
"data": [
{
"name": "9mobile 9Payment Service Bank",
"code": "120001"
},
{
"name": "Abbey Mortgage Bank",
"code": "404"
},
@GoodnessEzeokafor
GoodnessEzeokafor / NIbssistitutionlist
Created August 14, 2024 09:39 — forked from OlabodeAbesin/NIbssistitutionlist
Nigerian bank, bank/institution codes and logo
[
{
"id": 376,
"InstitutionCode": "090270",
"InstitutionName": "AB MICROFINANCE BANK",
"Category": "9",
"dump": null,
"created_at": "2020-03-02 20:44:54",
"updated_at": "2020-08-24 00:02:52",
"deleted_at": null,