Untitled

 avatar
user_4058768
plain_text
13 days ago
3.2 kB
2
Indexable
Never
module.exports = app => {
    const menu = {
        parentMenu: app.parentMenu.sdh,
        menus: {
            7646: {
                title: 'Quản lý nhập điểm', link: '/user/sau-dai-hoc/nhap-diem-hoc-phan', parentKey: 7543
            }
        }
    };

    app.permission.add(
        { name: 'sdhConfigHocPhan:read', menu },
        'sdhConfigHocPhan:write',
        'sdhConfigHocPhan:delete'
    );

    app.get('/user/sau-dai-hoc/nhap-diem-hoc-phan', app.permission.check('sdhConfigHocPhan:read'), app.templates.admin);
    app.get('/user/sdh/nhap-diem-hoc-phan/edit/:maHocPhan', app.permission.check('sdhConfigHocPhan:write'), app.templates.admin);

    //APIs----------------------------------------------------------------------------------------------------------------------------------

    app.get('/api/sdh/cau-hinh-hoc-phan/page/:pageNumber/:pageSize/:maHocPhan', app.permission.orCheck('sdhConfigHocPhan:read'), async (req, res) => {
        try {
            const { pageNumber, pageSize, maHocPhan } = req.params;
            let { filter } = req.query || {};
            filter = filter || {};
            const searchTerm = typeof req.query.condition === 'string' ? req.query.condition : '';

            const { rows: list, pagenumber, pagesize, pagetotal, totalitem } = await app.model.sdhConfigHocPhan.searchPage(Number(pageNumber), Number(pageSize), app.utils.stringify(filter), maHocPhan, searchTerm);
            res.send({ page: { list, pageNumber: pagenumber, pageSize: pagesize, pageTotal: pagetotal, totalItem: totalitem } });
        } catch (error) {
            app.consoleError(error);
            res.send({ error });
        }
    });

    app.get('/api/sdh/cau-hinh-hoc-phan/get-student', app.permission.check('sdhConfigHocPhan:read'), async (req, res) => {
        try {
            const { maHocPhan, filter } = req.query;
            let data = await app.model.sdhConfigHocPhan.getStudent(maHocPhan, app.utils.stringify(filter));
            data = data.rows.map(item => ({
                ...item,
                loaiDiem: app.utils.parse(item.diem)
            }));
            res.send(data);
        } catch (error) {
            app.consoleError(error);
            res.send({ error });
        }
    });

    app.get('/api/sdh/cau-hinh-hoc-phan/get-data', app.permission.check('sdhConfigHocPhan:read'), async (req, res) => {
        try {
            let items = req.query.filter;
            let { maMonHoc, maHocPhan } = items;

            // Tạo đối tượng filter từ các tham số query
            let filter = {
                maMonHoc: maMonHoc || null,
                maHocPhan: maHocPhan || null
            };
            console.log(filter, 'filter');
            let data = await app.model.sdhConfigHocPhan.getDataHocPhan(app.utils.stringify(filter));
            console.log(data, 'data');

            res.send({ dataConfigMonHoc: data.dataconfigmonhoc, dataConfigHocPhan: data.rows });
        } catch (error) {
            app.consoleError(error);
            res.send({ error });
        }
    });

};
Leave a Comment