Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
fix: db schema updates WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhaev26 committed Mar 15, 2024
1 parent cbd91b1 commit 1715ae0
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 190 deletions.
7 changes: 3 additions & 4 deletions apis/src/models/admin.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ export default function (app: Application): Model<any> {
const mongooseClient: Mongoose = app.get('mongooseClient');
const { Schema } = mongooseClient;
const schema = new Schema({
role: {
type: Number,
enum: RolesEnumList,
default: RolesEnum.ADMIN,
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'users'
},
player: {
type: mongoose.Schema.Types.ObjectId,
Expand Down
16 changes: 14 additions & 2 deletions apis/src/models/platform-super-admin.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@
// See http://mongoosejs.com/docs/models.html
// for more of what you can do here.
import { Application } from '../declarations';
import { Model, Mongoose } from 'mongoose';
import mongoose, { Model, Mongoose } from 'mongoose';

export default function (app: Application): Model<any> {
const modelName = 'platformSuperAdmin';
const mongooseClient: Mongoose = app.get('mongooseClient');
const { Schema } = mongooseClient;
const schema = new Schema({
text: { type: String, required: true }
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'users',
required: true,
},
contactNo: {
type: String
},
socials: [
{
type: Object
}
],
}, {
timestamps: true
});
Expand Down
39 changes: 3 additions & 36 deletions apis/src/models/player.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,16 @@ export default function (app: Application): Model<any> {
const mongooseClient: Mongoose = app.get('mongooseClient');
const { ObjectId } = mongoose.Schema.Types;
const schema = new mongooseClient.Schema({
firstName: {
type: String,
required: true
},
lastName: {
type: String,
required: true
},
email: {
type: String,
required: true,
index: true,
},
password: {
type: String,
required: true
},
role: {
type: Number,
enum: RolesEnumList,
default:RolesEnum.PLAYER
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'users',
},
sport: {
type: String,
required: true,
enum: SportEnumList,
index: true,
},
branch: {
type: String,
required: true,
enum: BranchEnumList,
index: true,
},
year: {
type: Number,
required: true,
enum: [1, 2, 3, 4],
index: true,
},
contactNo: {
type: String
},
socials: [
{
type: Object
Expand Down
5 changes: 5 additions & 0 deletions apis/src/models/squad-player.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export default function (app: Application): Model<any> {
const mongooseClient: Mongoose = app.get('mongooseClient');
const { Schema } = mongooseClient;
const schema = new Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'users',
required: true,
},
player: {
type: mongoose.Schema.Types.ObjectId,
ref: 'player',
Expand Down
34 changes: 22 additions & 12 deletions apis/src/models/team-player.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,28 @@ export default function (app: Application): Model<any> {
const mongooseClient: Mongoose = app.get('mongooseClient');
const { Schema } = mongooseClient;
const schema = new Schema({
team:{
type:mongoose.Schema.Types.ObjectId,
ref:'team',
required:true,
},
squad:{
type:mongoose.Schema.Types.ObjectId,
ref:'squad',
required:true,
},
position:{
type:String,
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'users',
required: true,
},
player: {
type: mongoose.Schema.Types.ObjectId,
ref: 'player',
required: true,
},
team: {
type: mongoose.Schema.Types.ObjectId,
ref: 'team',
required: true,
},
squad: {
type: mongoose.Schema.Types.ObjectId,
ref: 'squad',
required: true,
},
position: {
type: String,
},
createdBy: {
type: mongoose.Schema.Types.ObjectId,
Expand Down
43 changes: 38 additions & 5 deletions apis/src/models/users.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,51 @@
//
// See http://mongoosejs.com/docs/models.html
// for more of what you can do here.
import { BranchEnumList } from '../constants/branch.enum';
import RolesEnum, { RolesEnumList } from '../constants/roles.enum';
import { Application } from '../declarations';
import { Model, Mongoose } from 'mongoose';

export default function (app: Application): Model<any> {
const modelName = 'users';
const mongooseClient: Mongoose = app.get('mongooseClient');
const schema = new mongooseClient.Schema({

email: { type: String, unique: true, lowercase: true },
password: { type: String },


firstName: {
type: String,
required: true
},
lastName: {
type: String,
required: true
},
email: {
type: String,
required: true,
index: true,
},
password: {
type: String,
required: true
},
role: {
type: Number,
enum: RolesEnumList,
},
branch: {
type: String,
required: true,
enum: BranchEnumList,
index: true,
},
year: {
type: Number,
required: true,
enum: [1, 2, 3, 4],
index: true,
},
contactNo: {
type: String
},
}, {
timestamps: true
});
Expand Down
26 changes: 26 additions & 0 deletions apis/src/services/users/users.class.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
import { Service, MongooseServiceOptions } from 'feathers-mongoose';
import { Application } from '../../declarations';
import { Params } from '@feathersjs/feathers';
import generateOTP from '../../utils/generateOTP';
import { BadRequest } from '@feathersjs/errors';
import app from '../../app';
import RolesEnum from '../../constants/roles.enum';
import * as jwt from "jsonwebtoken"
import sendMail from '../../utils/sendMail';

export class Users extends Service {
//eslint-disable-next-line @typescript-eslint/no-unused-vars
constructor(options: Partial<MongooseServiceOptions>, app: Application) {
super(options);
}

async create(data: any, params: Params) {
try {
if (!data.email || !data.password) throw new BadRequest('Email and Password is required');
const otp = generateOTP();
const secret = app.settings.authentication.secret;
data.role = RolesEnum.PLAYER;
const token = jwt.sign({
player: data,
otp
}, secret);

await sendMail(data.email, otp);

return { token };
} catch (error: any) {
throw new Error(error.message);
}
}
}
26 changes: 13 additions & 13 deletions apis/src/services/users/verification/verification.class.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import { Id, NullableId, Paginated, Params, ServiceMethods } from '@feathersjs/feathers';
import { Id, NullableId, Paginated, Params, ServiceAddons, ServiceMethods } from '@feathersjs/feathers';
import { Application } from '../../../declarations';
import { extractTokenFromHeader } from '../../../utils/extractTokenFromHeader';
import { BadRequest } from '@feathersjs/errors';
import { Service } from 'feathers-mongoose';
import { Users } from '../users.class';

interface Data {}
interface Data { }

interface ServiceOptions {}
interface ServiceOptions { }

export class Verification implements ServiceMethods<Data> {
app: Application;
options: ServiceOptions;

constructor (options: ServiceOptions = {}, app: Application) {
constructor(options: ServiceOptions = {}, app: Application) {
this.options = options;
this.app = app;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async find (params?: Params): Promise<Data[] | Paginated<Data>> {
async find(params?: Params): Promise<Data[] | Paginated<Data>> {
return [];
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async get (id: Id, params?: Params): Promise<Data> {
async get(id: Id, params?: Params): Promise<Data> {
return {
id, text: `A new message with ID: ${id}!`
};
Expand All @@ -48,11 +49,10 @@ export class Verification implements ServiceMethods<Data> {

// @ts-ignore
if (otp === data.otp) {
const PlayerService: Service = this.app.service('player');
const UserService: Users & ServiceAddons<any> = this.app.service('users');
console.log(player);
const p = new PlayerService.Model(player);
const _p = await p.save();
return _p;
const user = await UserService._create(player);
return user
}
else throw new Error('OTP is invalid');
} catch (error: any) {
Expand All @@ -62,17 +62,17 @@ export class Verification implements ServiceMethods<Data> {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async update (id: NullableId, data: Data, params?: Params): Promise<Data> {
async update(id: NullableId, data: Data, params?: Params): Promise<Data> {
return data;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async patch (id: NullableId, data: Data, params?: Params): Promise<Data> {
async patch(id: NullableId, data: Data, params?: Params): Promise<Data> {
return data;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async remove (id: NullableId, params?: Params): Promise<Data> {
async remove(id: NullableId, params?: Params): Promise<Data> {
return { id };
}
}
Loading

0 comments on commit 1715ae0

Please sign in to comment.