Skip to content

Commit

Permalink
fix: prunned folder directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Homoakin619 committed Jul 23, 2024
1 parent 2b6c476 commit 359cd2e
Show file tree
Hide file tree
Showing 27 changed files with 445 additions and 251 deletions.
11 changes: 11 additions & 0 deletions config/appConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as dotenv from 'dotenv';

dotenv.config();

export const appConfig = {
jwt: {
jwtSecret: process.env.JWT_SECRET,
jwtExpiry: process.env.JWT_EXPIRY_TIMEFRAME
}

}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"start:prod": "node dist/src/main",
"dev": "PROFILE=local ./node_modules/.bin/ts-node-dev -r dotenv/config --respawn src/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
Expand All @@ -36,6 +36,8 @@
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.0.0",
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.3.9",
"@nestjs/swagger": "^7.3.1",
"@nestjs/typeorm": "^10.0.2",
Expand All @@ -44,6 +46,7 @@
"class-validator": "^0.14.1",
"joi": "^17.6.0",
"nestjs-pino": "^4.1.0",
"passport-jwt": "^4.0.1",
"pg": "^8.12.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
Expand All @@ -61,6 +64,7 @@
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/passport-jwt": "^4.0.1",
"@types/supertest": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
Expand All @@ -72,7 +76,7 @@
"lint-staged": "^15.2.5",
"prettier": "^3.0.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"supertest": "^6.3.4",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
Expand Down
6 changes: 5 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import dataSource from './database/data-source';
import { SeedingModule } from './database/seeding/seeding.module';
import HealthController from './health.controller';
import { AuthModule } from './modules/auth/auth.module';
import { UserModule } from './modules/user/user.module';

@Module({
providers: [
Expand Down Expand Up @@ -52,7 +54,9 @@ import HealthController from './health.controller';
dataSourceFactory: async () => dataSource,
}),
SeedingModule,
AuthModule,
UserModule
],
controllers: [HealthController],
})
export class AppModule {}
export class AppModule { }
17 changes: 1 addition & 16 deletions src/database/seeding/seeding.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SeedingService } from './seeding.service';

@Controller('seed')
export class SeedingController {
constructor(private readonly seedingService: SeedingService) {}
constructor(private readonly seedingService: SeedingService) { }

@Post()
async seedDatabase() {
Expand All @@ -15,19 +15,4 @@ export class SeedingController {
async getUsers() {
return this.seedingService.getUsers();
}

@Get('profiles')
async getProfiles() {
return this.seedingService.getProfiles();
}

@Get('products')
async getProducts() {
return this.seedingService.getProducts();
}

@Get('organisations')
async getOrganisations() {
return this.seedingService.getOrganisations();
}
}
9 changes: 3 additions & 6 deletions src/database/seeding/seeding.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ import { Module } from '@nestjs/common';
import { SeedingService } from './seeding.service';
import { SeedingController } from './seeding.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from 'src/entities/user.entity';
import { Profile } from 'src/entities/profile.entity';
import { Product } from 'src/entities/product.entity';
import { Organisation } from 'src/entities/organisation.entity';
import { User } from '../../modules/user/entities/user.entity';

@Module({
imports: [TypeOrmModule.forFeature([User, Profile, Product, Organisation])],
imports: [TypeOrmModule.forFeature([User])],
providers: [SeedingService],
controllers: [SeedingController],
})
export class SeedingModule {}
export class SeedingModule { }
98 changes: 4 additions & 94 deletions src/database/seeding/seeding.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Injectable } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { User } from 'src/entities/user.entity';
import { Profile } from 'src/entities/profile.entity';
import { Product } from 'src/entities/product.entity';
import { Organisation } from 'src/entities/organisation.entity';
import { User } from '../../modules/user/entities/user.entity';


@Injectable()
export class SeedingService {
constructor(private readonly dataSource: DataSource) {}
constructor(private readonly dataSource: DataSource) { }

async seedDatabase() {
const userRepository = this.dataSource.getRepository(User);
Expand All @@ -24,9 +22,7 @@ export class SeedingService {
await queryRunner.startTransaction();

try {
const profileRepository = this.dataSource.getRepository(Profile);
const productRepository = this.dataSource.getRepository(Product);
const organisationRepository = this.dataSource.getRepository(Organisation);


const u1 = userRepository.create({
first_name: 'John',
Expand All @@ -48,66 +44,6 @@ export class SeedingService {
throw new Error('Failed to create all users');
}

const p1 = profileRepository.create({
username: 'johnsmith',
bio: 'bio data',
phone: '1234567890',
avatar_image: 'image.png',
user: savedUsers[0],
});
const p2 = profileRepository.create({
username: 'janesmith',
bio: 'bio data',
phone: '0987654321',
avatar_image: 'image.png',
user: savedUsers[1],
});

await profileRepository.save([p1, p2]);

const savedProfiles = await profileRepository.find();
if (savedProfiles.length !== 2) {
throw new Error('Failed to create all profiles');
}

const pr1 = productRepository.create({
product_name: 'Product 1',
description: 'Description 1',
product_price: 100,
user: savedUsers[0],
});
const pr2 = productRepository.create({
product_name: 'Product 2',
description: 'Description 2',
product_price: 200,
user: savedUsers[1],
});

await productRepository.save([pr1, pr2]);

const savedProducts = await productRepository.find();
if (savedProducts.length !== 2) {
throw new Error('Failed to create all products');
}

const or1 = organisationRepository.create({
org_name: 'Org 1',
description: 'Description 1',
users: savedUsers,
});
const or2 = organisationRepository.create({
org_name: 'Org 2',
description: 'Description 2',
users: [savedUsers[0]],
});

await organisationRepository.save([or1, or2]);

const savedOrganisations = await organisationRepository.find();
if (savedOrganisations.length !== 2) {
throw new Error('Failed to create all organisations');
}

await queryRunner.commitTransaction();
} catch (error) {
await queryRunner.rollbackTransaction();
Expand All @@ -129,30 +65,4 @@ export class SeedingService {
}
}

async getProfiles(): Promise<Profile[]> {
try {
return this.dataSource.getRepository(Profile).find({ relations: ['user'] });
} catch (error) {
console.error('Error fetching profiles:', error.message);
throw error;
}
}

async getProducts(): Promise<Product[]> {
try {
return this.dataSource.getRepository(Product).find({ relations: ['user'] });
} catch (error) {
console.error('Error fetching products:', error.message);
throw error;
}
}

async getOrganisations(): Promise<Organisation[]> {
try {
return this.dataSource.getRepository(Organisation).find({ relations: ['users'] });
} catch (error) {
console.error('Error fetching organisations:', error.message);
throw error;
}
}
}
17 changes: 0 additions & 17 deletions src/entities/organisation.entity.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/entities/parent.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { BeforeInsert, Column, Entity, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';

@Entity()
export class Parent {
@PrimaryGeneratedColumn('uuid')
id: string;

@CreateDateColumn({ name: 'created_at' })
created_at: Date;

@UpdateDateColumn({ name: 'updated_at' })
updated_at: Date;
}
21 changes: 0 additions & 21 deletions src/entities/product.entity.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/entities/profile.entity.ts

This file was deleted.

70 changes: 0 additions & 70 deletions src/entities/user.entity.ts

This file was deleted.

Loading

0 comments on commit 359cd2e

Please sign in to comment.