UNPKG

phx-react

Version:

PHX REACT

539 lines (536 loc) • 13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FIND_CLASSROOM_BY_USER_IDS = exports.FIND_USER_INFO = exports.FIND_TEACHER_BY_USER_CODE = exports.FIND_STAFF_BY_USER_CODE = exports.FIND_STUDENT_BY_USER_CODE = exports.GET_CLASSROOM_BY_USER_IDS = exports.GET_LIST_ROLE_QUERY = exports.GET_TARGET_BY_ROLE_QUERY = exports.getTargetByIdQuery = exports.queryListUserBuilder = exports.GET_SELECT_QUERY = void 0; const constant_1 = require("../constant"); const target_1 = require("../type/target"); exports.GET_SELECT_QUERY = ` query getSelectQuery($schoolId: Int!, $schoolYearId: Int!) { educational_level(order_by: { id: asc }, where: { deleted_at: { _is_null: true }, school_id: { _eq: $schoolId } }) { id name code } grade( order_by: { id: asc } where: { deleted_at: { _is_null: true } school_id: { _eq: $schoolId } educational_level: { deleted_at: { _is_null: true } } } ) { id name code educational_level_id } classroom( order_by: { id: asc } where: { deleted_at: { _is_null: true } school_id: { _eq: $schoolId } grade: { educational_level: { deleted_at: { _is_null: true } } } school_year_id: { _eq: $schoolYearId } } ) { id name code grade { id educational_level_id } } department(where: { deleted_at: { _is_null: true }, school_id: { _eq: $schoolId } }) { id name } } `; const getFieldByTarget = (target, schoolYearId, schoolId) => { const fieldByTarget = { [constant_1.ERoleCode.TEACHER]: ` profile_teacher { user_code educational_level_group { educational_level_map_groups(where:{deleted_at:{_is_null:true}}) { educational_level_id } } teacher_subject_assignments(where: {deleted_at:{_is_null:true}}) { classroom_teachers(where: {deleted_at:{_is_null:true} classroom:{school_year_id:{_eq: ${schoolYearId}}}}) { teacher_type classroom { id grade_id } } } } `, [constant_1.ERoleCode.STAFF]: ` profile_staff { user_code educational_level_group { educational_level_map_groups(where:{deleted_at:{_is_null:true}}) { educational_level_id } } } `, [constant_1.ERoleCode.STUDENT]: ` profile_student { user_code grade { id name } program_map_educational_level { educational_level { code name id } } } classroom_students( where: { deleted_at: { _is_null: true } classroom: { deleted_at: { _is_null: true } school_year_id: { _eq: ${schoolYearId} } school_id: { _eq: ${schoolId} } } } ) { id classroom { id name grade_id grade { id educational_level_id } program_id school_year_id program { name } } } relationshipUsersByStudentId(order_by: {created_at: desc}, where: {deleted_at: {_is_null: true}, user: {deleted_at: {_is_null: true}}, userByStudentId: {deleted_at: {_is_null: true}}}) { parent_id relationship_code user { gender full_name phone_number } } `, [constant_1.ERoleCode.DEPARTMENT]: '', [constant_1.ERoleCode.PARENT]: '', }; return fieldByTarget[target]; }; const getConditionsByTarget = ({ target }) => { if (target === constant_1.ERoleCode.STAFF) { return ` ${`profile_staff:{ deleted_at:{_is_null:true} is_quit_job:{_eq:false} }`} `; } if (target === constant_1.ERoleCode.STUDENT) { return ` profile_student: { student_status: {_eq: ${target_1.EStudentStatus.STUDYING}}, deleted_at:{_is_null:true} } `; } if (target === constant_1.ERoleCode.TEACHER) { return ` profile_teacher: { is_quit_job: { _eq: false } deleted_at: { _is_null: true } } `; } return ''; }; const queryListUserBuilder = ({ schoolId, schoolYearId, target }) => ` query getListUserQuery( $roleCode: String! $limit: Int! $offset: Int! $searchKeyword: String! $schoolId: Int! ) { users( limit: $limit offset: $offset order_by: {created_at: desc, id:desc} where: { ${getConditionsByTarget({ target })} deleted_at: {_is_null: true} school_id:{_eq: $schoolId} user_roles: { deleted_at: {_is_null: true} role: {role_code: {_eq: $roleCode}} } _or: [ {full_name: {_ilike: $searchKeyword}} {full_name_unaccent: {_ilike: $searchKeyword}} ] } ) { id full_name email phone_number ${getFieldByTarget(target, schoolYearId, schoolId)} user_roles(where: {deleted_at: {_is_null: true}, is_active: {_eq: true}, role: {school_id: {_eq: $schoolId}}}) { role { name } } } }`; exports.queryListUserBuilder = queryListUserBuilder; exports.getTargetByIdQuery = ` query getTargetByIdQuery($id: uuid!) { target_inform_target_by_pk(id: $id) { target_by_roles(where: {deleted_at: {_is_null: true}}) { role_code target_educational_levels { educational_level { id name code } } target_grades { grade { id name code } } target_classrooms { classroom { id name code } } target_users { user { id name: full_name phone: phone_number email profile_teacher { user_code } profile_staff { user_code } } } } } } `; exports.GET_TARGET_BY_ROLE_QUERY = ` query getTargetByRoleQuery($id: uuid!) { user_segment_target_by_pk(id: $id) { school_year_id target_by_roles(where: {deleted_at: {_is_null: true}}) { role { role_code } is_all notify_with target_educational_levels { educational_level { id name code } } target_grades { grade { id name code } } target_classrooms { classroom { id name code } } target_departments { department { id name } } target_users { user { id name: full_name phone: phone_number email profile_student { user_code grade { id name } program_map_educational_level { educational_level { code name id } } } profile_teacher { user_code } profile_staff { user_code } relationshipUsersByStudentId( order_by: {created_at: desc} where: { deleted_at: {_is_null: true} user: {deleted_at: {_is_null: true}} userByStudentId: {deleted_at: {_is_null: true}} } ) { parent_id relationship_code user { gender full_name phone_number } } } } } } } `; exports.GET_LIST_ROLE_QUERY = ` query getListRoleQuery($schoolId: Int!) { role(where: {deleted_at: {_is_null: true}, school_id: {_eq: $schoolId}}) { id role_code } } `; exports.GET_CLASSROOM_BY_USER_IDS = ` query getClassroomByUserIds($schoolYearId: Int!, $userIds: [Int!]!) { classroom_student( where: { deleted_at: { _is_null: true } user:{id:{_in:$userIds}} classroom: { deleted_at: { _is_null: true } school_year_id: { _eq: $schoolYearId } } } ) { user{ id } classroom { id name grade_id grade { id educational_level_id } program_id school_year_id program { name } } } } `; exports.FIND_STUDENT_BY_USER_CODE = ` query FindStudentByUserCodes($userCodes: [String!]!, $schoolId: Int!) { allCoreStudentPublicProfileStudents( filter: { deletedAt: { isNull: true } userCode: { in: $userCodes } schoolId: { equalTo: $schoolId } } ) { pageInfo { endCursor hasNextPage hasPreviousPage startCursor } nodes { userCode gradeId studentId coreStudentPublicGradeByGradeIdAndSchoolId { name id: rowId } coreStudentPublicUserByStudentIdAndSchoolId { coreStudentPublicRelationshipUsersByStudentIdAndSchoolId( filter: { deletedAt: { isNull: true } schoolId: { equalTo: $schoolId } coreStudentPublicUserByParentIdAndSchoolId: { deletedAt: { isNull: true } schoolId: { equalTo: $schoolId } } } ) { nodes { parentId relationshipCode rowId } } } coreStudentPublicProgramMapEducationalLevelByProgramEducationalIdAndSchoolId { coreStudentPublicEducationalLevelByEducationalLevelIdAndSchoolId { code name id: rowId } } } } } `; exports.FIND_STAFF_BY_USER_CODE = ` query FindStaffByUserCodes($userCodes: [String!]!, $schoolId: Int!) { allCoreAdminPublicUsers( filter: { deletedAt: { isNull: true } schoolId: { equalTo: $schoolId } coreAdminPublicProfileStaffByStaffIdAndSchoolId: { userCode: { in: $userCodes } deletedAt: { isNull: true } schoolId: { equalTo: $schoolId } } } ) { pageInfo { endCursor hasNextPage hasPreviousPage startCursor } nodes { id: rowId fullName phoneNumber emailSecondary email isUseEmailSecondary coreAdminPublicProfileStaffByStaffIdAndSchoolId { userCode } } } } `; exports.FIND_TEACHER_BY_USER_CODE = ` query FindTeacherByUserCodes($userCodes: [String!]!, $schoolId: Int!) { allCoreAdminPublicProfileTeachers( filter: { deletedAt: { isNull: true } userCode: { in: $userCodes } schoolId: { equalTo: $schoolId } } ) { pageInfo { endCursor hasNextPage hasPreviousPage startCursor } nodes { userCode coreAdminPublicEducationalLevelGroupByEducationalLevelGroupIdAndSchoolId { id: rowId name schoolId } coreAdminPublicUserByTeacherIdAndSchoolId { email emailSecondary fullName id: rowId phoneNumber isUseEmailSecondary isEmailValid isEmailSecondaryValid } } } } `; exports.FIND_USER_INFO = ` query findUserInfo($ids: [Int!]!, $schoolId: Int!) { allCoreAdminPublicUsers( filter: { rowId: {in: $ids} deletedAt: {isNull: true} schoolId: {equalTo: $schoolId} } ) { nodes { email fullName isEmailValid isEmailSecondaryValid isUseEmailSecondary id: rowId } } } `; exports.FIND_CLASSROOM_BY_USER_IDS = ` query FindClassroomByUserIds($userIds: [Int!]!, $schoolYearId: Int!, $schoolId: Int!) { allCoreAcademicPublicClassroomStudents( filter: { deletedAt: {isNull: true} coreAcademicPublicClassroomByClassroomIdAndSchoolId: { schoolYearId: {equalTo: $schoolYearId} } studentId: { in: $userIds } schoolId: { equalTo: $schoolId } } ) { nodes { coreAcademicPublicClassroomByClassroomIdAndSchoolId { name rowId } studentId } } } `; //# sourceMappingURL=query.js.map