Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/models/batch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import jagql, {BaseType} from '@jagql/framework'
import {getHandler} from '../../handlers/sqlHandler'
import {Center} from '../center'
import {Course} from '../course'
import {Teacher} from '../teacher'
import ValidateIdHandler from './validateIdHandler'

const Joi = jagql.Joi
Expand All @@ -10,6 +11,7 @@ export interface Batch {
id: string
center: Center | BaseType
course: Course | BaseType
teacher: Teacher | BaseType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be of array type

startDate?: Date
endDate?: Date
lectureStartTime?: string
Expand All @@ -27,6 +29,7 @@ jagql.define<Batch>({
id: Joi.string().max(8),
center: Joi.one('centers'),
course: Joi.one('courses'),
teacher: Joi.many('teachers'),
startDate: Joi.date(),
endDate: Joi.date(),
lectureStartTime: Joi.string().length(4).regex(/([01]?[0-9]|2[0-3])[0-5][0-9]/),
Expand All @@ -37,6 +40,7 @@ jagql.define<Batch>({
id: 'CBPP18S1', type: 'batches',
course: {type: 'courses', id: 'CB'},
center: {type: 'centers', id: 'PP'},
teacher: {type: 'teachers', id: 'AR'},
lectureStartTime: '1000', lectureEndTime: '1400',
startDate: new Date('2018-03-18'),
endDate: new Date('2018-04-15'),
Expand Down
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './batch'
import './center'
import './course'
import './teacher'
34 changes: 34 additions & 0 deletions src/models/teacher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import jagql from '@jagql/framework'
import {getHandler} from '../handlers/sqlHandler';
import {Batch} from './batch'

const Joi = jagql.Joi
const handler = getHandler()

export interface Teacher {
name: string
id: string
contactNo?: string
email?: string
batches?: Batch[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly batches entiy should have teachers: Teachers[] field too now right ?

}

jagql.define <Teacher>({
resource: 'teachers',
primaryKey: 'string',
handlers: handler,
namespace: 'cb',
attributes: {
name: Joi.string().required(),
id: Joi.string().length(2).required(),
contactNo: Joi.string().allow(null),
email: Joi.string().email().allow(null),
batches: Joi.belongsToMany({resource: 'batches', as: 'center'}),
},
examples: [
{id: 'AG', name: 'Arnav Gupta', type: 'teachers'},
{id: 'PR', name: 'Prateek Narang', type: 'teachers'},
],
})

handler.populate({force: true})