Skip to content

Commit

Permalink
Merge branch 'dev' into feature-exclude-deleted-organisations
Browse files Browse the repository at this point in the history
  • Loading branch information
dainty92 authored Mar 1, 2025
2 parents 14613ea + fa685bc commit 7f45365
Show file tree
Hide file tree
Showing 80 changed files with 2,283 additions and 570 deletions.
46 changes: 19 additions & 27 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
NODE_ENV=development
PROFILE=local
PORT=5000
HOST=
REDIS_PORT= 6379
DB_SSL=true
NODE_ENV=development

PORT=3008

JWT_SECRET=someSecrets
JWT_EXPIRY_TIMEFRAME=3600


REDIS_HOST=localhost
REDIS_PORT=6379
DB_TYPE=

DB_TYPE=postgres
DB_USERNAME=
DB_PASSWORD=
DB_HOST=
DB_NAME=hng
DB_HOST=localhost
DB_DATABASE=
DB_ENTITIES=dist/src/modules/**/entities/**/*.entity{.ts,.js}
DB_MIGRATIONS=dist/db/migrations/*{.ts,.js}
POSGRES_USER=$DB_USERNAME
POST
JWT_SECRET=gsgs
JWT_EXPIRY_TIMEFRAME=1500000
DB_SSL=false
JWT_REFRESH_SECRET=bbp
JWT_REFRESH_EXPIRY_TIMEFRAME=15
GOOGLE_REDIRECT_URI=

JWT_SECRET=someSecrets
JWT_EXPIRY_TIMEFRAME=3600

ADMIN_SECRET_KEY=sometext

GOOGLE_CLIENT_SECRET=
GOOGLE_CLIENT_ID=
OAUTH_LOGIN_REDIRECT=
SMTP_HOST=

SMTP_HOST=sandbox.smtp.mailtrap.io
SMTP_PORT=587
SERVER_NAME=Boilerplate
SERVER_NAME=api
SMTP_USER=
SMTP_PASSWORD=
FRONTEND_URL=
ADMIN_SECRET=
SUPPORT_EMAIL=
AUTH_PASSWORD=
BASE_URL=
FLUTTERWAVE_SECRET_KEY=
FLUTTERWAVE_BASE_URL=
SMTP_PASSWORD=
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ NODE_ENV=development
PORT=3000

DB_USERNAME=username
DB_PASSWORD=password
DB_PASSWORD=password123
DB_TYPE=postgres
DB_NAME=database
DB_HOST=localhost
Expand Down
38 changes: 35 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ fabric.properties
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore


# DB
data/db/

docker-compose.yml
# User-specific files
*.suo
*.user
Expand Down Expand Up @@ -386,7 +391,6 @@ Network Trash Folder
Temporary Items
.apdisk

=======
# Local
dist
/.env
Expand All @@ -401,8 +405,36 @@ dist
*.dev
*.prod

data/db/

# User specific ignores
todo.txt
/.vscode/
.vscode/

# Docker compose
docker-compose.yml
data/
data/
docker-compose.yml
package-lock.json
.dev.env


package-lock.json
docker-compose.yml
data/
.dev.env

/compose/compose.yaml
compose/compose.yaml

data/
docker-compose.yml
package-lock.json/
package-lock.json
.dev.env


package-lock.json
docker-compose.yml
data/
.dev.env
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"source.fixAll": "explicit"
},
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
"editor.defaultFormatter": "vscode.typescript-language-features"
}
}
65 changes: 0 additions & 65 deletions compose/compose.yaml

This file was deleted.

8 changes: 8 additions & 0 deletions config/s3.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { registerAs } from '@nestjs/config';

export default registerAs('s3', () => ({
accessKey: process.env.AWS_ACCESS_KEY || '',
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || '',
region: process.env.AWS_REGION || 'us-east-2',
bucketName: process.env.AWS_S3_BUCKET_NAME || '',
}));
6 changes: 6 additions & 0 deletions local repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
gerge branch 'dev' into feat/s3-resume-upload
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,22 @@
"postinstall": "npm install --platform=linux --arch=x64 sharp"
},
"dependencies": {
"@css-inline/css-inline": "^0.14.1",
"@css-inline/css-inline-linux-x64-gnu": "^0.14.1",
"@faker-js/faker": "^8.4.1",
"@google/generative-ai": "^0.17.0",
"@nestjs/axios": "^3.0.2",
"@nestjs/bull": "^10.2.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.10",
"@google/generative-ai": "^0.22.0",
"@nestjs/axios": "^4.0.0",
"@nestjs/bull": "^11.0.2",
"@nestjs/config": "^4.0.0",
"@nestjs/core": "^11.0.10",
"@nestjs/jwt": "^11.0.0",
"@nestjs/passport": "^11.0.5",
"@nestjs/platform-express": "^11.0.10",
"@nestjs/schedule": "^5.0.1",
"@nestjs/serve-static": "^5.0.3",
"@nestjs/swagger": "^7.4.0",
"@nestjs/typeorm": "^10.0.2",
"@types/nodemailer": "^6.4.15",
"@types/speakeasy": "^2.0.10",
"@vitalets/google-translate-api": "^9.2.1",
"aws-sdk": "^2.1692.0",
"bcrypt": "^5.1.1",
"bcryptjs": "^3.0.2",
"bull": "^4.16.5",
Expand All @@ -61,7 +60,7 @@
"file-type-mime": "^0.4.6",
"google-auth-library": "^9.15.1",
"handlebars": "^4.7.8",
"html-validator": "^6.0.1",
"html-validator": "^5.1.18",
"ioredis": "^5.5.0",
"joi": "^17.13.3",
"module-alias": "^2.2.3",
Expand Down
4 changes: 2 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
import { LanguageGuard } from '@guards/language.guard';
import { ApiStatusModule } from '@modules/api-status/api-status.module';

import s3Config from '@config/s3.config';
@Module({
providers: [
{
Expand Down Expand Up @@ -82,7 +82,7 @@ import { ApiStatusModule } from '@modules/api-status/api-status.module';
*/
envFilePath: ['.env.development.local', `.env.${process.env.PROFILE}`],
isGlobal: true,
load: [serverConfig, authConfig],
load: [serverConfig, authConfig, s3Config],
validationSchema: Joi.object({
NODE_ENV: Joi.string().valid('development', 'production', 'test', 'provision').required(),
PROFILE: Joi.string().valid('local', 'development', 'production', 'ci', 'testing', 'staging').required(),
Expand Down
35 changes: 31 additions & 4 deletions src/database/seeding/seeding.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,43 @@ export class SeedingService {
async createSuperAdmin({ secret, ...adminDetails }: CreateAdminDto): Promise<CreateAdminResponseDto> {
try {
const userRepository = this.dataSource.getRepository(User);
const roleRepository = this.dataSource.getRepository(Role);
const orgUserRoleRepository = this.dataSource.getRepository(OrganisationUserRole);

// Check if user exists
const exists = await userRepository.findOne({ where: { email: adminDetails.email } });
if (exists) throw new ConflictException('A user already exist with the same email');

const user = userRepository.create(adminDetails);
// Verify admin secret
const { ADMIN_SECRET } = process.env;
if (secret !== ADMIN_SECRET) throw new UnauthorizedException(INVALID_ADMIN_SECRET);

// user.user_type = UserType.SUPER_ADMIN;
const admin = await userRepository.save(user);
return { status: 201, message: ADMIN_CREATED, data: admin };
// Find or create super-admin role
let adminRole = await roleRepository.findOne({ where: { name: 'super-admin' } });
if (!adminRole) {
adminRole = roleRepository.create({
name: 'super-admin',
description: 'Super Administrator',
});
adminRole = await roleRepository.save(adminRole);
}

// Create and save user
const user = userRepository.create(adminDetails);
const savedUser = await userRepository.save(user);

// Assign super-admin role to user
const userRole = orgUserRoleRepository.create({
userId: savedUser.id,
roleId: adminRole.id,
});
await orgUserRoleRepository.save(userRole);

return {
status: 201,
message: ADMIN_CREATED,
data: savedUser,
};
} catch (error) {
console.log('Error creating superAdmin:', error);
if (error instanceof UnauthorizedException || error instanceof ConflictException) throw error;
Expand Down
29 changes: 29 additions & 0 deletions src/guards/job-owner.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Job } from '../modules/jobs/entities/job.entity';

@Injectable()
export class JobOwnerGuard implements CanActivate {
constructor(
@InjectRepository(Job)
private readonly jobRepository: Repository<Job>
) {}

async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest();
const jobId = request.params.id;
const userId = request.user.sub;

if (!jobId || !userId) return false;

const job = await this.jobRepository.findOne({
where: { id: jobId },
relations: ['user'],
});

if (!job) return false;

return job.user.id === userId;
}
}
Loading

0 comments on commit 7f45365

Please sign in to comment.