Skip to content

Commit

Permalink
fix(next/api): export author.nickname
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjdd committed Jan 16, 2024
1 parent 00b4e1e commit 8fbc49a
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions next/api/src/ticket/export/ExportTicket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,30 +188,31 @@ const format = (date?: Date, utcOffset?: number) => {
);
};

const getCategories = async (authOptions?: AuthOptions) => {
const getCategories = async () => {
const categories = await categoryService.find();
return _(categories).keyBy('id').valueOf();
return _.keyBy(categories, (c) => c.id);
};

const getCategoryPath = async (category: Category) => {
const parents = await categoryService.getParentCategories(category.id);
return [...parents.map((c) => c.name).reverse(), category.name].join('/');
};

const getCustomerServices = async () => {
const customerServices = await User.getCustomerServices();
return _(customerServices)
.map((user) => new UserResponse(user).toJSON())
.keyBy('id')
.valueOf();
const encodeUser = (user: User) => {
return {
id: user.id,
username: user.username,
nickname: user.name,
email: user.email,
};
};

const getGroups = async (authOptions?: AuthOptions) => {
const groups = await Group.query().find(authOptions);
return _(groups)
.map((group) => new GroupResponse(group).toJSON())
.keyBy('id')
.valueOf();
const encodeGroup = (group: Group) => {
return {
id: group.id,
name: group.name,
description: group.description,
};
};

const getReplies = async (ticketIds: string[], authOptions?: AuthOptions, utcOffset?: number) => {
Expand Down Expand Up @@ -349,8 +350,6 @@ export default async function exportTicket({ params, sortItems, utcOffset, date
const count = await query.count(authOptions);
debug('count: ', count);
const categoryMap = await getCategories();
const customerServiceMap = await getCustomerServices();
const groupMap = await getGroups(authOptions);
const getCustomFormFields = getCustomFormFieldsFunc(authOptions);
let fieldKeys: string[] = [];

Expand All @@ -359,6 +358,8 @@ export default async function exportTicket({ params, sortItems, utcOffset, date
for (let index = 0; index < count; index += limit) {
const tickets = await (await createTicketQuery(containFields, query, index, limit))
.preload('author', { authOptions })
.preload('assignee', { authOptions })
.preload('group', { authOptions })
.find(authOptions);
const ticketIds = tickets.map((ticket) => ticket.id);
debug('fetch ticket details', ticketIds);
Expand All @@ -375,9 +376,7 @@ export default async function exportTicket({ params, sortItems, utcOffset, date
debug('form values fetched');
for (let ticketIndex = 0; ticketIndex < tickets.length; ticketIndex++) {
const ticket = tickets[ticketIndex];
const assignee = ticket.assigneeId ? customerServiceMap[ticket.assigneeId] : undefined;
const category = categoryMap[ticket.categoryId];
const group = ticket.groupId ? groupMap[ticket.groupId] : undefined;
const fields = fieldValuesMap[ticket.id]?.values.map(({ field, value }) => ({
id: field,
title: fieldCacheMap.get(field),
Expand All @@ -398,8 +397,9 @@ export default async function exportTicket({ params, sortItems, utcOffset, date
}
const data = {
..._.pick(ticket, FIXED_KEYS),
assignee,
group,
author: ticket.author && encodeUser(ticket.author),
assignee: ticket.assignee && encodeUser(ticket.assignee),
group: ticket.group && encodeGroup(ticket.group),
category: {
id: category?.id,
name: category?.name,
Expand Down

0 comments on commit 8fbc49a

Please sign in to comment.