Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "stellarAid-api",
"name": "stellaraid-api",
"version": "0.0.1",
"description": "",
"author": "",
Expand All @@ -17,7 +17,11 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:e2e": "jest --config ./test/jest-e2e.json",
"typeorm": "typeorm-ts-node-commonjs",
"migration:generate": "npm run typeorm -- migration:generate -d src/database/data-source.ts",
"migration:run": "npm run typeorm -- migration:run -d src/database/data-source.ts",
"migration:revert": "npm run typeorm -- migration:revert -d src/database/data-source.ts"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.1015.0",
Expand All @@ -31,12 +35,12 @@
"@nestjs/swagger": "^11.2.6",
"@nestjs/typeorm": "^11.0.0",
"@types/ejs": "^3.1.5",
"@types/multer": "^2.1.0",
"@types/nodemailer": "^7.0.11",
"@types/uuid": "^10.0.0",
"bcrypt": "^5.1.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.4",
"dotenv": "^17.3.1",
"ejs": "^4.0.1",
"joi": "^18.0.2",
"multer": "^2.1.1",
Expand All @@ -61,6 +65,7 @@
"@types/bcrypt": "^5.0.2",
"@types/express": "^5.0.0",
"@types/jest": "^30.0.0",
"@types/multer": "^2.1.0",
"@types/node": "^22.10.7",
"@types/passport-jwt": "^4.0.1",
"@types/supertest": "^6.0.2",
Expand Down Expand Up @@ -97,6 +102,11 @@
"testEnvironment": "node",
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/src/$1"
},
"globals": {
"ts-jest": {
"tsconfig": "tsconfig.spec.json"
}
}
}
}
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import configuration from './database/config';
import { LoggerModule } from './logger/logger.module';
import { ProjectsModule } from './projects/projects.module';
import { MailModule } from './mail/mail.module';
import { DonationsModule } from './donations/donations.module';

@Module({
imports: [
Expand All @@ -24,6 +25,7 @@ import { MailModule } from './mail/mail.module';
// Users module provides user-facing endpoints such as change-password
UsersModule,
ProjectsModule,
DonationsModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
1 change: 1 addition & 0 deletions src/common/services/file-upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { S3Client, PutObjectCommand, DeleteObjectCommand } from '@aws-sdk/client
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { ConfigService } from '@nestjs/config';
import { randomUUID } from 'crypto';
import { File } from 'buffer';

@Injectable()
export class FileUploadService {
Expand Down
17 changes: 17 additions & 0 deletions src/database/data-source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DataSource } from 'typeorm';
import * as dotenv from 'dotenv';

dotenv.config();

export default new DataSource({
type: 'postgres',
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT || '5432', 10),
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
entities: ['dist/**/*.entity{.ts,.js}'],
migrations: ['src/database/migrations/*.ts'],
synchronize: false,
logging: true,
});
127 changes: 127 additions & 0 deletions src/database/migrations/1711382400000-CreateDonationsTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableIndex } from 'typeorm';

export class CreateDonationsTable1711382400000 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'donations',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'projectId',
type: 'uuid',
},
{
name: 'donorId',
type: 'uuid',
isNullable: true,
},
{
name: 'amount',
type: 'decimal',
precision: 18,
scale: 7,
},
{
name: 'assetType',
type: 'varchar',
default: "'XLM'",
},
{
name: 'transactionHash',
type: 'varchar',
isNullable: true,
isUnique: true,
},
{
name: 'isAnonymous',
type: 'boolean',
default: false,
},
{
name: 'createdAt',
type: 'timestamp',
default: 'CURRENT_TIMESTAMP',
},
],
}),
true,
);

// Create indexes
await queryRunner.createIndex(
'donations',
new TableIndex({
name: 'IDX_donations_project_id',
columnNames: ['projectId'],
}),
);

await queryRunner.createIndex(
'donations',
new TableIndex({
name: 'IDX_donations_transaction_hash',
columnNames: ['transactionHash'],
}),
);

// Create foreign keys
await queryRunner.createForeignKey(
'donations',
new TableForeignKey({
name: 'FK_donations_project',
columnNames: ['projectId'],
referencedTableName: 'projects',
referencedColumnNames: ['id'],
onDelete: 'CASCADE',
}),
);

await queryRunner.createForeignKey(
'donations',
new TableForeignKey({
name: 'FK_donations_donor',
columnNames: ['donorId'],
referencedTableName: 'users',
referencedColumnNames: ['id'],
onDelete: 'SET NULL',
}),
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
const table = await queryRunner.getTable('donations');

if (table) {
// Drop foreign keys
const projectForeignKey = table.foreignKeys.find(fk => fk.name === 'FK_donations_project');
if (projectForeignKey) {
await queryRunner.dropForeignKey('donations', projectForeignKey);
}

const donorForeignKey = table.foreignKeys.find(fk => fk.name === 'FK_donations_donor');
if (donorForeignKey) {
await queryRunner.dropForeignKey('donations', donorForeignKey);
}

// Drop indexes
const projectIdIndex = table.indices.find(idx => idx.name === 'IDX_donations_project_id');
if (projectIdIndex) {
await queryRunner.dropIndex('donations', projectIdIndex);
}

const transactionHashIndex = table.indices.find(idx => idx.name === 'IDX_donations_transaction_hash');
if (transactionHashIndex) {
await queryRunner.dropIndex('donations', transactionHashIndex);
}
}

await queryRunner.dropTable('donations');
}
}
Loading
Loading