fixing export activity log
This commit is contained in:
@ -12,6 +12,7 @@ import * as fastcsv from 'fast-csv';
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { UserActivity } from "entity";
|
import { UserActivity } from "entity";
|
||||||
import exceljs from "exceljs";
|
import exceljs from "exceljs";
|
||||||
|
import { ActivityTypeReverse } from "entity/src/types/action";
|
||||||
|
|
||||||
const log: Logger<ILogObj> = new Logger({ name: '[UserActivityController]', type: 'pretty' });
|
const log: Logger<ILogObj> = new Logger({ name: '[UserActivityController]', type: 'pretty' });
|
||||||
|
|
||||||
@ -96,9 +97,6 @@ export class UserActivityController {
|
|||||||
whereVal['id_user'] = req.auth.data.id;
|
whereVal['id_user'] = req.auth.data.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const res_count = userRepository.createQueryBuilder()
|
|
||||||
// .leftJoinAndMapOne('u.username', User, 'u', 'u.id = id_user')
|
|
||||||
// .where(whereAttr, whereVal);
|
|
||||||
const res_count = userRepository.createQueryBuilder('user_activity')
|
const res_count = userRepository.createQueryBuilder('user_activity')
|
||||||
.leftJoinAndSelect("user_activity.application", "application")
|
.leftJoinAndSelect("user_activity.application", "application")
|
||||||
.leftJoinAndSelect("user_activity.user", "user")
|
.leftJoinAndSelect("user_activity.user", "user")
|
||||||
@ -106,17 +104,6 @@ export class UserActivityController {
|
|||||||
const res_list = userRepository.createQueryBuilder('user_activity')
|
const res_list = userRepository.createQueryBuilder('user_activity')
|
||||||
.leftJoinAndSelect("user_activity.application", "application")
|
.leftJoinAndSelect("user_activity.application", "application")
|
||||||
.leftJoinAndSelect("user_activity.user", "user")
|
.leftJoinAndSelect("user_activity.user", "user")
|
||||||
// .select(
|
|
||||||
// 'id,\n\
|
|
||||||
// id_user,\n\
|
|
||||||
// module,\n\
|
|
||||||
// description,\n\
|
|
||||||
// action,\n\
|
|
||||||
// url,\n\
|
|
||||||
// application,\n\
|
|
||||||
// created_at')
|
|
||||||
// .addSelect('(SELECT u.username FROM users u WHERE u.id = id_user)', 'username')
|
|
||||||
// .leftJoinAndMapOne('u.username', User, 'u', 'u.id = id_user')
|
|
||||||
.where(whereAttr, whereVal)
|
.where(whereAttr, whereVal)
|
||||||
.orderBy(param.order_field, param.order_direction)
|
.orderBy(param.order_field, param.order_direction)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
@ -213,7 +200,8 @@ export class UserActivityController {
|
|||||||
{ header: "Description", key: "description", width: 25 },
|
{ header: "Description", key: "description", width: 25 },
|
||||||
{ header: "Action", key: "action", width: 10 },
|
{ header: "Action", key: "action", width: 10 },
|
||||||
{ header: "Url", key: "url", width: 25 },
|
{ header: "Url", key: "url", width: 25 },
|
||||||
{ header: "Created At", key: "created_at", width: 15 }
|
{ header: "Created At", key: "created_at", width: 15 },
|
||||||
|
{ header: "By", key: "by", width: 20 }
|
||||||
];
|
];
|
||||||
|
|
||||||
const limit = 50;
|
const limit = 50;
|
||||||
@ -221,24 +209,52 @@ export class UserActivityController {
|
|||||||
const fetchAndWrite = async (page: number) => {
|
const fetchAndWrite = async (page: number) => {
|
||||||
const offset = (page - 1) * limit
|
const offset = (page - 1) * limit
|
||||||
|
|
||||||
const data = await repo.createQueryBuilder()
|
// const data = await repo.createQueryBuilder()
|
||||||
|
// .where(whereAttr, whereVal)
|
||||||
|
// .select([
|
||||||
|
// 'module',
|
||||||
|
// 'description',
|
||||||
|
// 'action',
|
||||||
|
// 'url',
|
||||||
|
// 'created_at'])
|
||||||
|
// .addSelect('(SELECT u.username FROM users u WHERE u.id = id_user)', 'username')
|
||||||
|
// .orderBy(param.order_field, param.order_direction)
|
||||||
|
// .offset(offset)
|
||||||
|
// .limit(limit).getRawMany();
|
||||||
|
|
||||||
|
const data = await repo.createQueryBuilder('user_activity')
|
||||||
|
.leftJoinAndSelect("user_activity.application", "application")
|
||||||
|
.leftJoinAndSelect("user_activity.user", "user")
|
||||||
.where(whereAttr, whereVal)
|
.where(whereAttr, whereVal)
|
||||||
.select([
|
|
||||||
'module',
|
|
||||||
'description',
|
|
||||||
'action',
|
|
||||||
'url',
|
|
||||||
'created_at'])
|
|
||||||
.addSelect('(SELECT u.username FROM users u WHERE u.id = id_user)', 'username')
|
|
||||||
.orderBy(param.order_field, param.order_direction)
|
.orderBy(param.order_field, param.order_direction)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(limit).getRawMany();
|
.limit(param.limit).getMany();
|
||||||
|
|
||||||
if (CommonHelper.countObject(data) === 0) {
|
if (CommonHelper.countObject(data) === 0) {
|
||||||
sheet.commit();
|
sheet.commit();
|
||||||
workbook.commit();
|
workbook.commit();
|
||||||
} else {
|
} else {
|
||||||
data.forEach((item: any) => sheet.addRow(item).commit());
|
interface ds {
|
||||||
|
module: string,
|
||||||
|
description: string
|
||||||
|
action: string
|
||||||
|
url: any
|
||||||
|
created_at: Date
|
||||||
|
by: string
|
||||||
|
}
|
||||||
|
|
||||||
|
data.forEach((item: UserActivity) => {
|
||||||
|
const di: ds = {
|
||||||
|
module: item.module,
|
||||||
|
description: item.description,
|
||||||
|
action: ActivityTypeReverse[item.action],
|
||||||
|
created_at: item.created_at,
|
||||||
|
by: item.user.username,
|
||||||
|
url: item.url
|
||||||
|
}
|
||||||
|
|
||||||
|
sheet.addRow(di).commit()
|
||||||
|
});
|
||||||
|
|
||||||
if (CommonHelper.countObject(data) == limit) {
|
if (CommonHelper.countObject(data) == limit) {
|
||||||
fetchAndWrite(page + 1);
|
fetchAndWrite(page + 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user