Skip to content

Commit 894cb33

Browse files
committed
feat: set body
1 parent 910bff6 commit 894cb33

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,16 @@ export class PostsRepository {
265265
});
266266
}
267267

268-
async changeState(id: string, state: State, err?: string) {
268+
async changeState(id: string, state: State, err?: any, body?: any) {
269269
const update = await this._post.model.post.update({
270270
where: {
271271
id,
272272
},
273273
data: {
274274
state,
275-
error: typeof err === 'string' ? err : JSON.stringify(err),
275+
...(err
276+
? { error: typeof err === 'string' ? err : JSON.stringify(err) }
277+
: {}),
276278
},
277279
include: {
278280
integration: {
@@ -283,14 +285,15 @@ export class PostsRepository {
283285
},
284286
});
285287

286-
if (state === 'ERROR') {
288+
if (state === 'ERROR' && err && body) {
287289
try {
288290
await this._errors.model.errors.create({
289291
data: {
290292
message: typeof err === 'string' ? err : JSON.stringify(err),
291293
organizationId: update.organizationId,
292294
platform: update.integration.providerIdentifier,
293295
postId: update.id,
296+
body: typeof body === 'string' ? body : JSON.stringify(body),
294297
},
295298
});
296299
} catch (err) {}

libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ export class PostsService {
282282
}
283283

284284
async post(id: string) {
285-
const [firstPost, ...morePosts] = await this.getPostsRecursively(id, true);
285+
const allPosts = await this.getPostsRecursively(id, true);
286+
const [firstPost, ...morePosts] = allPosts;
286287
if (!firstPost) {
287288
return;
288289
}
@@ -337,7 +338,7 @@ export class PostsService {
337338
return;
338339
}
339340
} catch (err: any) {
340-
await this._postRepository.changeState(firstPost.id, 'ERROR', err);
341+
await this._postRepository.changeState(firstPost.id, 'ERROR', err, allPosts);
341342
if (err instanceof BadBody) {
342343
await this._notificationService.inAppNotification(
343344
firstPost.organizationId,

libraries/nestjs-libraries/src/database/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ model ThirdParty {
643643
model Errors {
644644
id String @id @default(uuid())
645645
message String
646+
body String @default("{}")
646647
platform String
647648
organizationId String
648649
organization Organization @relation(fields: [organizationId], references: [id])

0 commit comments

Comments
 (0)