Skip to content

Commit 3b84480

Browse files
fix: include reports in response
1 parent 51ec01e commit 3b84480

File tree

6 files changed

+18039
-12847
lines changed

6 files changed

+18039
-12847
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strapi-plugin-comments",
3-
"version": "3.0.15",
3+
"version": "3.0.16",
44
"description": "Strapi - Comments plugin",
55
"strapi": {
66
"name": "comments",

server/src/controllers/__tests__/client.controller.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ describe('Client controller', () => {
123123
expect(mockCommonService.findAllFlat).toHaveBeenCalledWith({
124124
...validatedData,
125125
populate: {
126+
reports: {
127+
where: {
128+
resolved: false,
129+
},
130+
},
126131
threadOf: {
127132
populate: {
128133
authorUser: true
@@ -167,6 +172,11 @@ describe('Client controller', () => {
167172
expect(mockCommonService.findAllInHierarchy).toHaveBeenCalledWith({
168173
...validatedData,
169174
populate: {
175+
reports: {
176+
where: {
177+
resolved: false,
178+
},
179+
},
170180
threadOf: {
171181
populate: {
172182
authorUser: true
@@ -205,6 +215,11 @@ describe('Client controller', () => {
205215
expect(mockCommonService.findAllPerAuthor).toHaveBeenCalledWith({
206216
...validatedData,
207217
populate: {
218+
reports: {
219+
where: {
220+
resolved: false,
221+
},
222+
},
208223
threadOf: {
209224
populate: {
210225
authorUser: true
@@ -237,6 +252,11 @@ describe('Client controller', () => {
237252
expect(mockCommonService.findAllPerAuthor).toHaveBeenCalledWith({
238253
...validatedData,
239254
populate: {
255+
reports: {
256+
where: {
257+
resolved: false,
258+
},
259+
},
240260
threadOf: {
241261
populate: {
242262
authorUser: true

server/src/controllers/__tests__/utils/parser.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ describe('Parser', () => {
1313
related: undefined,
1414
},
1515
populate: {
16+
reports: {
17+
where: {
18+
resolved: false,
19+
},
20+
},
1621
threadOf: {
1722
populate: {
1823
authorUser: true,
@@ -65,6 +70,11 @@ describe('Parser', () => {
6570
related: undefined,
6671
},
6772
populate: {
73+
reports: {
74+
where: {
75+
resolved: false,
76+
},
77+
},
6878
threadOf: {
6979
populate: {
7080
authorUser: true,
@@ -87,6 +97,11 @@ describe('Parser', () => {
8797
expect(result.populate).toEqual({
8898
authorUser: true,
8999
comments: true,
100+
reports: {
101+
where: {
102+
resolved: false,
103+
},
104+
},
90105
threadOf: {
91106
populate: {
92107
authorUser: true,
@@ -112,6 +127,11 @@ describe('Parser', () => {
112127
related: 'some-relation',
113128
},
114129
populate: {
130+
reports: {
131+
where: {
132+
resolved: false,
133+
},
134+
},
115135
threadOf: {
116136
populate: {
117137
authorUser: true,
@@ -124,6 +144,7 @@ describe('Parser', () => {
124144
it('should handle complex populate configuration', () => {
125145
const input = {
126146
populate: {
147+
reports: { populate: true },
127148
author: { populate: true },
128149
comments: { populate: true },
129150
reactions: true,
@@ -133,11 +154,13 @@ describe('Parser', () => {
133154
const result = flatInput(input);
134155

135156
expect(result.populate).toEqual({
157+
reports: { populate: true },
136158
authorUser: { populate: true },
137159
comments: { populate: true },
138160
reactions: true,
139161
threadOf: {
140162
populate: {
163+
reports: { populate: true },
141164
authorUser: { populate: true },
142165
comments: { populate: true },
143166
reactions: true,
@@ -173,6 +196,11 @@ describe('Parser', () => {
173196
related: undefined,
174197
},
175198
populate: {
199+
reports: {
200+
where: {
201+
resolved: false,
202+
},
203+
},
176204
threadOf: {
177205
populate: {
178206
authorUser: true,
@@ -207,6 +235,11 @@ describe('Parser', () => {
207235
related: undefined,
208236
},
209237
populate: {
238+
reports: {
239+
where: {
240+
resolved: false,
241+
},
242+
},
210243
threadOf: {
211244
populate: {
212245
authorUser: true,
@@ -247,6 +280,11 @@ describe('Parser', () => {
247280
related: undefined,
248281
},
249282
populate: {
283+
reports: {
284+
where: {
285+
resolved: false,
286+
},
287+
},
250288
threadOf: {
251289
populate: {
252290
authorUser: true,

server/src/controllers/utils/parsers.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PopulateSchema } from '../../validators/api/controllers/client.controller.validator';
12
import { client } from '../../validators/api';
23
import { omit as omitLodash } from 'lodash';
34

@@ -38,7 +39,12 @@ export const flatInput = <T extends FlatInputParams>(payload: T): T => {
3839
);
3940
const hasRemoved = filters.$or?.some((item) => item.removed);
4041

41-
let basePopulate = {
42+
let basePopulate: PopulateSchema = {
43+
reports: {
44+
where: {
45+
resolved: false,
46+
},
47+
},
4248
...populate,
4349
};
4450

@@ -58,6 +64,11 @@ export const flatInput = <T extends FlatInputParams>(payload: T): T => {
5864
if ('author' in populate) {
5965
const { author, ...restPopulate } = populate;
6066
basePopulate = {
67+
reports: {
68+
where: {
69+
resolved: false,
70+
},
71+
},
6172
...restPopulate,
6273
authorUser: author,
6374
};

server/src/validators/api/controllers/client.controller.validator.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ const paginationSchema = z.object({
5454
}).optional(),
5555
});
5656

57+
// TODO when Strapi will use zod v4 we can change it to the z.stringbool()
58+
const populateSchema = z
59+
.record(z.union([
60+
z.union([
61+
z.boolean(),
62+
z.literal("true").transform(() => true),
63+
z.literal("false").transform(() => false),
64+
z.literal("*")
65+
]),
66+
z.record(z.any()),
67+
]))
68+
.optional()
69+
70+
export type PopulateSchema = z.infer<typeof populateSchema>;
71+
5772
const getBaseFindSchema = (enabledCollections: string[]) => {
5873
// $or: [{ approvalStatus: "APPROVED" }, { isAdminComment: true }],
5974
const filters = getFiltersOperators({
@@ -84,9 +99,7 @@ const getBaseFindSchema = (enabledCollections: string[]) => {
8499
)
85100
.optional(),
86101
isAdmin: z.boolean().optional().default(false),
87-
populate: z
88-
.record(z.union([z.boolean(), z.object({ populate: z.boolean() })]))
89-
.optional(),
102+
populate: populateSchema,
90103
limit: stringToNumberValidator.optional(),
91104
skip: stringToNumberValidator.optional(),
92105
locale: z.string().optional(),

0 commit comments

Comments
 (0)