@@ -6,6 +6,8 @@ import dbConfig from '../../config/database';
66import Project from '../models/Project' ;
77import Class from '../models/Class' ;
88import ClassProfessional from '../models/ClassProfessional' ;
9+ import ClassProject from '../models/ClassProject' ;
10+ import Child from '../models/Child' ;
911
1012const sequelize = new Sequelize ( dbConfig . database , dbConfig . username ,
1113 dbConfig . password , { host : dbConfig . host , dialect : dbConfig . dialect } ) ;
@@ -56,8 +58,6 @@ class TeacherController extends UserController {
5658 } ,
5759 } ) ;
5860
59- console . log ( relations ) ;
60-
6161 for ( const relation of relations ) {
6262 const class_obj = await Class . findByPk ( relation . dataValues . fk_idClass ) ;
6363 list . push ( class_obj . dataValues ) ;
@@ -68,6 +68,49 @@ class TeacherController extends UserController {
6868 return res . status ( 500 ) . json ( { error : err . stack } ) ;
6969 }
7070 }
71+
72+ async getClassInfo ( req , res ) {
73+ try {
74+ const { class_id } = req . params ;
75+
76+ const relation = await ClassProfessional . findOne ( {
77+ where : {
78+ fk_idClass : class_id ,
79+ fk_idProfessional : req . userId ,
80+ } ,
81+ } ) ;
82+ if ( relation === null ) {
83+ return res . status ( 403 ) . json ( { message : 'Esta turma não é sua ou não existe.' } ) ;
84+ }
85+
86+ const details = await Class . findByPk ( class_id ) ;
87+
88+ const activities = [ ] ;
89+ const activities_rels = await ClassProject . findAll ( {
90+ where : {
91+ fk_idClass : class_id ,
92+ } ,
93+ } ) ;
94+ for ( const relation of activities_rels ) {
95+ const project = await Project . findByPk ( relation . dataValues . fk_idProject ) ;
96+ activities . push ( project . dataValues ) ;
97+ }
98+
99+ const children = await Child . findAll ( {
100+ where : {
101+ fk_idClass : class_id ,
102+ } ,
103+ } ) ;
104+
105+ return res . json ( {
106+ details,
107+ activities,
108+ children,
109+ } ) ;
110+ } catch ( err ) {
111+ return res . status ( 500 ) . json ( { error : err . stack } ) ;
112+ }
113+ }
71114}
72115
73116export default new TeacherController ( ) ;
0 commit comments