forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity-feed.controller.ts
More file actions
71 lines (68 loc) · 2.11 KB
/
Copy pathactivity-feed.controller.ts
File metadata and controls
71 lines (68 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Controller, Get, Param, Query } from "@nestjs/common";
import { ActivityFeedService } from "./activity-feed.service";
import {
ActivityEventDto,
ActivityFeedQuery,
PaginatedActivityEvents,
} from "./dto/activity-event.dto";
import { Auth, CurrentUser } from "../auth/guard/auth.guard";
import { User } from "../users/user.entity";
import { PrismaService } from "../prisma/prisma.service";
@Controller("activity-feed")
export class ActivityFeedController {
constructor(
private readonly activityFeedService: ActivityFeedService,
private readonly prisma: PrismaService,
) {}
/**
* Get paginated activity events for the authenticated merchant.
* Ordered newest first.
*
* Query params:
* - Offset paging: `page`, `limit`
* - Cursor paging: `cursor`, `pageSize`, `before`
* - Filters: `type`, `startDate`, `endDate`, `invoiceId`
*/
@Auth()
@Get()
async findAll(
@CurrentUser() user: User,
@Query("page") page?: string,
@Query("limit") limit?: string,
@Query("pageSize") pageSize?: string,
@Query("cursor") cursor?: string,
@Query("before") before?: string,
@Query("type") type?: string,
@Query("startDate") startDate?: string,
@Query("endDate") endDate?: string,
@Query("invoiceId") invoiceId?: string,
): Promise<PaginatedActivityEvents> {
const query: ActivityFeedQuery = {
page: page ? parseInt(page, 10) : undefined,
limit: limit ? parseInt(limit, 10) : undefined,
pageSize: pageSize ? parseInt(pageSize, 10) : undefined,
cursor,
before: before === "true" || before === "1",
type,
startDate,
endDate,
invoiceId,
};
return this.prisma.runWithMerchantScope(user.merchantId, () =>
this.activityFeedService.findAll(user.merchantId, query),
);
}
/**
* Get a single activity event by ID.
*/
@Auth()
@Get(":id")
async findOne(
@CurrentUser() user: User,
@Param("id") id: string,
): Promise<ActivityEventDto | null> {
return this.prisma.runWithMerchantScope(user.merchantId, () =>
this.activityFeedService.findOne(id, user.merchantId),
);
}
}