Skip to content

Commit

Permalink
Merge pull request #113 from infinitybase/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
guimroque authored Jun 12, 2024
2 parents 983eff6 + 0d99cf9 commit 3e308f3
Show file tree
Hide file tree
Showing 23 changed files with 376 additions and 296 deletions.
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache-2.0",
"scripts": {
"dev": "NODE_ENV=development ts-node-dev --respawn --transpile-only -r tsconfig-paths/register -r dotenv/config src/server/index.ts",
"test": "NODE_ENV=test node --experimental-vm-modules ./node_modules/jest/bin/jest.js --setupFiles dotenv/config --runInBand",
"test": "NODE_ENV=test node --experimental-vm-modules ./node_modules/jest/bin/jest.js --setupFiles dotenv/config --runInBand ",
"start": "pm2-runtime start ./build/server/index.js",
"build": "tsc --project . && tscpaths -p tsconfig.json -s ./src -o ./build",
"copyFiles": "copyfiles --error --up 1 src/**/*.html build",
Expand Down Expand Up @@ -50,7 +50,7 @@
"socket.io-client": "4.7.5",
"ts-node": "^10.9.2",
"tsconfig-paths": "^3.15.0",
"typeorm": "^0.2.45",
"typeorm": "0.3.20",
"typescript": "^4.9.5"
},
"devDependencies": {
Expand Down
22 changes: 6 additions & 16 deletions packages/api/src/config/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ const development: ConnectionOptions = {
database: DATABASE_NAME,
entities: [entitiesDir],
migrations: [migrationsDir, seedersDir],
cli: {
entitiesDir: './src/models/',
migrationsDir: './src/database/migrations/',
},
synchronize: false,
migrationsRun: true,
};
Expand All @@ -59,10 +55,6 @@ const test: ConnectionOptions = {
database: DATABASE_NAME,
entities: [entitiesDir],
migrations: [migrationsDir, seedersDir],
cli: {
entitiesDir: './src/models/',
migrationsDir: './src/database/migrations/',
},
synchronize: false,
migrationsRun: true,
};
Expand All @@ -76,11 +68,10 @@ const production: ConnectionOptions = {
database: process.env.DATABASE_NAME,
entities: [entitiesDir],
migrations: [migrationsDir, seedersDir],
cli: {
entitiesDir: './src/models/',
migrationsDir: './src/database/migrations/',
},
synchronize: false,
ssl: {
rejectUnauthorized: false,
},
migrationsRun: true,
};

Expand All @@ -93,11 +84,10 @@ const staging: ConnectionOptions = {
database: process.env.DATABASE_NAME,
entities: [entitiesDir],
migrations: [migrationsDir, seedersDir],
cli: {
entitiesDir: './src/models/',
migrationsDir: './src/database/migrations/',
},
synchronize: false,
ssl: {
rejectUnauthorized: false,
},
migrationsRun: true,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export class updatePredicateVersion1714734332092 implements MigrationInterface {
const defaultPredicateVersion = await queryRunner.manager.findOne(
PredicateVersion,
{
code: predicateVersion.code,
where: {
code: predicateVersion.code,
},
},
);

Expand Down
10 changes: 9 additions & 1 deletion packages/api/src/database/seeders/110820231840-create-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ import { IconUtils } from '@utils/icons';
export default async function () {
const users = await generateInitialUsers();
for await (const user of users) {
const _user = await User.create(user).save();
const _user = await User.create(user)
.save()
.then(async _ => {
return await User.findOne({
order: {
createdAt: 'DESC',
},
});
});

await Workspace.create({
name: `singleWorkspace[${_user.id}]`,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/middlewares/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function authMiddleware(req: Request, res: Response, next: NextFunction) {
await recover.save();
requestAuth.user = recover.owner;
requestAuth.workspace = await Workspace.findOne({
where: { owner: recover.owner.id, single: true }, // just single workspace
where: { owner: recover.owner, single: true }, // just single workspace
});

return next();
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/mocks/initialSeeds/initialPredicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export const generateInitialPredicate = async (): Promise<Partial<Predicate>> =>
},
});
const version = await PredicateVersion.findOne({
code: predicateVersionMock.code,
where: {
code: predicateVersionMock.code,
},
});

const predicate1: Partial<Predicate> = {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/modules/auth/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class AuthController {
try {
const { address } = req.params;
const { origin } = req.headers;
const owner = await User.findOne({ address: address });
const owner = await User.findOne({ where: { address } });

const response = await new RecoverCodeService().create({
owner,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/modules/dApps/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class DappController {

return successful(true, Responses.Created);
} catch (e) {
console.log('[ERRO AO CRIAR]: ', e);
return error(e.error, e.statusCode);
}
}
Expand Down
38 changes: 20 additions & 18 deletions packages/api/src/modules/dApps/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { ErrorTypes } from '@src/utils/error';
import Internal from '@src/utils/error/Internal';

import { IDAPPCreatePayload, IDAppsService } from './types';
import { DeepPartial } from 'typeorm';

export class DAppsService implements IDAppsService {
async create(params: IDAPPCreatePayload) {
return await DApp.create(params)
const partialPayload: DeepPartial<DApp> = params;
return await DApp.create(partialPayload)
.save()
.then(data => data)
.then(() => this.findLast())
.catch(e => {
throw new Internal({
type: ErrorTypes.Internal,
Expand Down Expand Up @@ -63,20 +65,20 @@ export class DAppsService implements IDAppsService {
});
}

// async checkExist(address: string, sessionId, url: string) {
// return await DApp.createQueryBuilder('d')
// .innerJoin('d.users', 'users')
// .where('users.address = :address', { address })
// .andWhere('d.session_id = :sessionId', { sessionId })
// .andWhere('d.url = :url', { url })
// .getOne()
// .then(data => data)
// .catch(e => {
// throw new Internal({
// type: ErrorTypes.Internal,
// title: 'Error on find active sessions to dapp',
// detail: e,
// });
// });
// }
async findLast() {
try {
return await DApp.createQueryBuilder('d')
.select()
.innerJoinAndSelect('d.vaults', 'vaults')
.innerJoinAndSelect('d.currentVault', 'currentVault')
.orderBy('d.createdAt', 'DESC')
.getOne();
} catch (e) {
throw new Internal({
type: ErrorTypes.Internal,
title: 'Error on find last dapp',
detail: e,
});
}
}
}
22 changes: 20 additions & 2 deletions packages/api/src/modules/notification/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
INotificationService,
IUpdateNotificationPayload,
} from './types';
import { DeepPartial } from 'typeorm';
import { VaultTemplate } from '@src/models/VaultTemplate';

export class NotificationService implements INotificationService {
private _pagination: PaginationParams;
Expand All @@ -38,9 +40,10 @@ export class NotificationService implements INotificationService {
}

async create(payload: ICreateNotificationPayload): Promise<Notification> {
return await Notification.create(payload)
const partialPayload: DeepPartial<Notification> = payload;
return await Notification.create(partialPayload)
.save()
.then(notification => notification)
.then(() => this.findLast())
.catch(e => {
throw new Internal({
type: ErrorTypes.Internal,
Expand Down Expand Up @@ -94,4 +97,19 @@ export class NotificationService implements INotificationService {
});
});
}

async findLast(): Promise<Notification> {
return await Notification.createQueryBuilder('notification')
.select()
.orderBy('notification.createdAt', 'DESC')
.getOne()
.then(data => data)
.catch(e => {
throw new Internal({
type: ErrorTypes.Internal,
title: 'Error on notification find last',
detail: e,
});
});
}
}
Loading

0 comments on commit 3e308f3

Please sign in to comment.