Skip to content

Commit

Permalink
ft: refactors and implement attendance (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
aimedivin authored Oct 4, 2024
1 parent 86738fd commit 96e1ef6
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 144 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"graphql-subscriptions": "^2.0.0",
"graphql-tag": "^2.12.6",
"graphql-upload-ts": "^2.1.2",
"graphql-ws": "^5.11.2",
"graphql-ws": "^5.16.0",
"jsonwebtoken": "^9.0.2",
"mongodb": "^4.17.1",
"mongoose": "^6.6.1",
Expand Down
58 changes: 41 additions & 17 deletions src/models/attendance.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,55 @@ import mongoose, { Schema } from 'mongoose'

const AttendanceSchema = new Schema({
week: {
type: String,
type: Number,
required: true,
},
coordinatorId: {
type: [mongoose.Types.ObjectId],
ref: 'User',
phase: {
type: mongoose.Types.ObjectId,
ref: 'Phase',
required: true,
},
cohort: {
type: mongoose.Types.ObjectId,
ref: 'Cohort',
required: true,
},
trainees: [

teams: [
{
traineeId: {
type: [mongoose.Types.ObjectId],
ref: 'User',
},
traineeEmail: {
type: String,
requried: false,
team: {
type: mongoose.Types.ObjectId,
ref: 'Team',
required: true
},
status: [
trainees: [
{
days: String,
value: Number,
trainee: {
type: mongoose.Types.ObjectId,
ref: 'User',
},
status: [
{
day: {
type: String,
enum: ['mon', 'tue', 'wed', 'thu', 'fri'],
required: true
},
date: {
type: Date,
required: true
},
score: {
type: String,
enum: ['0', '1', '2'],
required: true
},
},
],
},
],
},
],}
],

})

const Attendance = mongoose.model('Attendance', AttendanceSchema)
Expand Down
15 changes: 15 additions & 0 deletions src/models/cohort.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import mongoose, { Schema } from 'mongoose'
import { User } from './user'
import { PhaseInterface } from './phase.model';

export interface CohortInterface {
_id: mongoose.Types.ObjectId;
name: string;
phase: PhaseInterface;
coordinator: mongoose.Types.ObjectId;
members: mongoose.Types.ObjectId[];
program: mongoose.Types.ObjectId;
teams: number;
active: boolean;
startDate: Date;
endDate?: Date; // Optional
organization: mongoose.Types.ObjectId;
}

const cohortSchema = new Schema(
{
Expand Down
7 changes: 7 additions & 0 deletions src/models/phase.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import mongoose, { Schema } from 'mongoose';

export interface PhaseInterface {
_id: mongoose.Types.ObjectId;
name: string;
description: string;
organization: mongoose.Types.ObjectId;
}

const phaseSchema = new Schema({
name: {
type: String,
Expand Down
11 changes: 11 additions & 0 deletions src/models/team.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import mongoose, { Schema } from 'mongoose'
import { User } from './user'
import { CohortInterface } from './cohort.model';

export interface TeamInterface {
name: string;
cohort?: CohortInterface;
ttl?: mongoose.Types.ObjectId;
members: mongoose.Types.ObjectId[];
startingPhase: Date;
active: boolean;
organization: mongoose.Types.ObjectId;
}

const teamSchema = new Schema(
{
Expand Down
20 changes: 20 additions & 0 deletions src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@ import bcrypt from 'bcryptjs'
import mongoose, { model, Schema } from 'mongoose'
import { Profile } from './profile.model'

export interface UserStatus {
status: 'active' | 'drop';
reason?: string;
date?: Date;
}

export interface UserInterface {
_id: mongoose.Types.ObjectId;
email: string;
password: string;
role: string;
team?: mongoose.Types.ObjectId;
status: UserStatus;
cohort?: mongoose.Types.ObjectId;
program?: mongoose.Types.ObjectId;
organizations: string[];
pushNotifications: boolean;
emailNotifications: boolean;
}

mongoose.set('toJSON', {
virtuals: true,
versionKey: false,
Expand Down
Loading

0 comments on commit 96e1ef6

Please sign in to comment.