Skip to content

Commit

Permalink
fix: moves core to new service structure,schema WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhaev26 committed Mar 14, 2024
1 parent 899c3ed commit 9af79d3
Show file tree
Hide file tree
Showing 81 changed files with 31 additions and 7,983 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 31 additions & 5 deletions apis/src/services/users/verification/verification.class.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Id, NullableId, Paginated, Params, ServiceMethods } from '@feathersjs/feathers';
import { Application } from '../../../declarations';
import { extractTokenFromHeader } from '../../../utils/extractTokenFromHeader';
import { BadRequest } from '@feathersjs/errors';
import { Service } from 'feathers-mongoose';

interface Data {}

Expand Down Expand Up @@ -27,12 +30,35 @@ export class Verification implements ServiceMethods<Data> {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async create (data: Data, params?: Params): Promise<Data> {
if (Array.isArray(data)) {
return Promise.all(data.map(current => this.create(current, params)));
}
async create(data: Data, params?: Params): Promise<Data> {
try {
// @ts-ignore
if (!data?.otp) throw new BadRequest('OTP not provided');
if (!params) throw new Error('Params not found at verification/create');

return data;
const token: string | null = extractTokenFromHeader(params);

if (!token) throw new BadRequest('Authentication Token Empty');
const secret = this.app.settings.authentication.secret;

// @ts-ignore
const { player, otp } = jwt.decode(token, secret);
console.log('player = ', player);
if (!player) throw new BadRequest('Invalid Token');

// @ts-ignore
if (otp === data.otp) {
const PlayerService: Service = this.app.service('player');
console.log(player);
const p = new PlayerService.Model(player);
const _p = await p.save();
return _p;
}
else throw new Error('OTP is invalid');
} catch (error: any) {
console.log(error);
throw new Error(error.message);
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions core/.editorconfig

This file was deleted.

38 changes: 0 additions & 38 deletions core/.eslintrc.json

This file was deleted.

112 changes: 0 additions & 112 deletions core/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion core/Dockerfile

This file was deleted.

Loading

0 comments on commit 9af79d3

Please sign in to comment.