Skip to content

Commit e70e856

Browse files
authored
feat: use yazl for export actions of items (#1914)
* feat: use yazl for export actions of items * refactor: refactor code * refactor: remove file * refactor: refactor code * refactor: use action export format locally * refactor: apply PR requested changes * refactor: update code
1 parent d554c01 commit e70e856

33 files changed

Lines changed: 1042 additions & 2077 deletions

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"@sentry/tracing": "7.120.3",
7474
"@sinclair/typebox": "0.34.33",
7575
"ajv": "8.17.1",
76-
"archiver": "7.0.1",
7776
"bcrypt": "5.1.1",
7877
"bullmq": "5.46.1",
7978
"date-fns": "4.1.0",
@@ -129,7 +128,6 @@
129128
"@jest/globals": "29.7.0",
130129
"@quobix/vacuum": "0.17.0",
131130
"@trivago/prettier-plugin-sort-imports": "5.2.2",
132-
"@types/archiver": "6.0.2",
133131
"@types/bad-words": "3.0.3",
134132
"@types/bcrypt": "5.0.2",
135133
"@types/checksum": "0.1.35",

src/drizzle/schema.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ export const actionViewEnum = pgEnum('action_view_enum', [
3838
'auth',
3939
'unknown',
4040
]);
41-
export const actionRequestExportFormatEnum = pgEnum('action_request_export_format_enum', [
42-
'json',
43-
'csv',
44-
]);
41+
export const actionRequestExportFormats = ['json', 'csv'] as const;
42+
export const actionRequestExportFormatEnum = pgEnum(
43+
'action_request_export_format_enum',
44+
actionRequestExportFormats,
45+
);
4546
export const itemExportRequestTypeEnum = pgEnum('item_export_request_type_enum', ['raw', 'graasp']);
4647
export const chatMentionStatusEnum = pgEnum('chat_mention_status_enum', ['unread', 'read']);
4748
export const shortLinkPlatformEnum = pgEnum('short_link_platform_enum', [

src/drizzle/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ export type MemberProfileRaw = typeof memberProfilesTable.$inferSelect;
334334
export type MemberProfileInsertDTO = typeof memberProfilesTable.$inferInsert;
335335

336336
export type ActionRequestExportRaw = typeof actionRequestExportsTable.$inferSelect;
337+
export type ActionRequestExportFormat = ActionRequestExportRaw['format'];
337338

338339
export type ItemExportRequestRaw = typeof itemExportRequestsTable.$inferSelect;
339340

src/services/action/action.repository.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ export class ActionRepository {
9191
andConditions.push(eq(actionsTable.accountId, filters.accountId));
9292
}
9393
// subquery for items descendants of the itemPath queried
94-
const itemSub = await dbConnection
94+
const itemSub = dbConnection
9595
.select()
9696
.from(items)
9797
.where(isDescendantOrSelf(items.path, itemPath))
9898
.as('item');
99+
99100
const res = await dbConnection
100101
.select()
101102
.from(actionsTable)

src/services/action/types.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
11
import { type Lookup, lookup } from 'geoip-lite';
22

3-
import { AggregateFunction, AggregateMetric, type UnionOfConst } from '@graasp/sdk';
4-
53
export const getGeolocationIp = (ip: string | number): Lookup | null => lookup(ip);
6-
7-
export const aggregateExpressionNames = {
8-
user: 'action.account_id',
9-
actionType: 'action.type',
10-
actionLocation: 'action.geolocation',
11-
itemId: 'action.item_id',
12-
createdDay: "date_trunc('day', action.createdAt)",
13-
createdTimeOfDay: 'extract(hour from action.created_at)',
14-
createdDayOfWeek: 'extract(dow from action.created_at)',
15-
} as const;
16-
export type AggregateExpressionValuesOptions = UnionOfConst<typeof aggregateExpressionNames>;
17-
18-
export const buildAggregateExpression = (
19-
subqueryName: string,
20-
func?: AggregateFunction,
21-
metric?: AggregateMetric,
22-
): string => {
23-
return `${func}(${subqueryName}."${metric}")`;
24-
};

src/services/action/utils/errors.ts

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -17,80 +17,3 @@ export class CannotWriteFileError extends GraaspActionError {
1717
);
1818
}
1919
}
20-
21-
export class InvalidAggregationError extends GraaspActionError {
22-
constructor(message?: string) {
23-
super({
24-
code: 'GPAERR002',
25-
statusCode: StatusCodes.BAD_REQUEST,
26-
message: 'The query parameters for the aggregation are invalid: ' + message,
27-
});
28-
}
29-
}
30-
31-
export class AggregateByCannotUserError extends GraaspActionError {
32-
constructor(data?: unknown) {
33-
super(
34-
{
35-
code: 'GPAERR003',
36-
statusCode: StatusCodes.BAD_REQUEST,
37-
message: 'aggregate by cannot be "user"',
38-
},
39-
data,
40-
);
41-
}
42-
}
43-
44-
export class AggregateByCannotIncludeAggregateMetricError extends GraaspActionError {
45-
constructor(data?: unknown) {
46-
super(
47-
{
48-
code: 'GPAERR004',
49-
statusCode: StatusCodes.BAD_REQUEST,
50-
message: 'aggregateBy cannot include aggregateMetric',
51-
},
52-
data,
53-
);
54-
}
55-
}
56-
57-
// todo: not sure of the name, I'm not sure what it really does
58-
export class CountGroupByShouldIncludeAggregateMetricError extends GraaspActionError {
59-
constructor(data?: unknown) {
60-
super(
61-
{
62-
code: 'GPAERR005',
63-
statusCode: StatusCodes.BAD_REQUEST,
64-
message:
65-
"countGroupBy should include aggregateMetric, except for aggregateMetric !== 'actionCount'",
66-
},
67-
data,
68-
);
69-
}
70-
}
71-
72-
export class CountGroupByShouldIncludeAggregateByError extends GraaspActionError {
73-
constructor(data?: unknown) {
74-
super(
75-
{
76-
code: 'GPAERR006',
77-
statusCode: StatusCodes.BAD_REQUEST,
78-
message: 'countGroupBy should include aggregateBy, unless it is actionCount',
79-
},
80-
data,
81-
);
82-
}
83-
}
84-
85-
export class InvalidAggregateFunctionError extends GraaspActionError {
86-
constructor(data?: unknown) {
87-
super(
88-
{
89-
code: 'GPAERR007',
90-
statusCode: StatusCodes.BAD_REQUEST,
91-
message: 'aggregateFunction cannot be applied on aggregateMetric=actionCount',
92-
},
93-
data,
94-
);
95-
}
96-
}

src/services/action/utils/export-utils.test.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/services/action/utils/export.test.ts

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)