Skip to content

Commit 23eade2

Browse files
committed
chore: fix services
1 parent b7bf95b commit 23eade2

File tree

6 files changed

+90
-16
lines changed

6 files changed

+90
-16
lines changed

platforms/cerberus/src/services/CharterSignatureService.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ export class CharterSignatureService {
253253
}
254254

255255
// Set charter as inactive
256-
await this.groupRepository.update(groupId, { isCharterActive: false });
256+
const group = await this.groupRepository.findOne({ where: { id: groupId } });
257+
if (group) {
258+
group.isCharterActive = false;
259+
await this.groupRepository.save(group);
260+
}
257261

258262
// Delete all existing signatures
259263
await this.signatureRepository.delete({ groupId });

platforms/cerberus/src/services/GroupService.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@ export class GroupService {
2020
}
2121

2222
async updateGroup(id: string, groupData: Partial<Group>): Promise<Group | null> {
23-
await this.groupRepository.update(id, groupData);
24-
return await this.getGroupById(id);
23+
// Get the current group, merge the data, and save it to trigger ORM events
24+
const currentGroup = await this.getGroupById(id);
25+
if (!currentGroup) {
26+
throw new Error("Group not found");
27+
}
28+
29+
// Merge the new data with the existing group
30+
Object.assign(currentGroup, groupData);
31+
32+
// Save the merged group to trigger ORM subscribers
33+
const updatedGroup = await this.groupRepository.save(currentGroup);
34+
return updatedGroup;
2535
}
2636

2737
async saveGroup(group: Group): Promise<Group> {

platforms/cerberus/src/services/MessageService.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,18 @@ export class MessageService {
8989
}
9090

9191
async updateMessage(id: string, messageData: Partial<Message>): Promise<Message | null> {
92-
await this.messageRepository.update(id, messageData);
93-
return await this.getMessageById(id);
92+
// Get the current message, merge the data, and save it to trigger ORM events
93+
const currentMessage = await this.getMessageById(id);
94+
if (!currentMessage) {
95+
throw new Error("Message not found");
96+
}
97+
98+
// Merge the new data with the existing message
99+
Object.assign(currentMessage, messageData);
100+
101+
// Save the merged message to trigger ORM subscribers
102+
const updatedMessage = await this.messageRepository.save(currentMessage);
103+
return updatedMessage;
94104
}
95105

96106
async deleteMessage(id: string): Promise<boolean> {
@@ -99,15 +109,26 @@ export class MessageService {
99109
}
100110

101111
async getUserMessages(userId: string): Promise<Message[]> {
102-
return await this.messageRepository.find({
112+
const messages = await this.messageRepository.find({
103113
where: { sender: { id: userId } },
104114
relations: ['sender', 'group'],
105115
order: { createdAt: 'DESC' }
106116
});
117+
118+
return messages;
107119
}
108120

109121
async archiveMessage(id: string): Promise<Message | null> {
110-
await this.messageRepository.update(id, { isArchived: true });
111-
return await this.getMessageById(id);
122+
// Get the current message, set archived flag, and save it to trigger ORM events
123+
const currentMessage = await this.getMessageById(id);
124+
if (!currentMessage) {
125+
throw new Error("Message not found");
126+
}
127+
128+
currentMessage.isArchived = true;
129+
130+
// Save the updated message to trigger ORM subscribers
131+
const archivedMessage = await this.messageRepository.save(currentMessage);
132+
return archivedMessage;
112133
}
113134
}

platforms/cerberus/src/services/UserService.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,18 @@ export class UserService {
5151
}
5252

5353
async updateUser(id: string, userData: Partial<User>): Promise<User | null> {
54-
await this.userRepository.update(id, userData);
55-
return await this.getUserById(id);
54+
// Get the current user, merge the data, and save it to trigger ORM events
55+
const currentUser = await this.getUserById(id);
56+
if (!currentUser) {
57+
throw new Error("User not found");
58+
}
59+
60+
// Merge the new data with the existing user
61+
Object.assign(currentUser, userData);
62+
63+
// Save the merged user to trigger ORM subscribers
64+
const updatedUser = await this.userRepository.save(currentUser);
65+
return updatedUser;
5666
}
5767

5868
async saveUser(user: User): Promise<User> {

platforms/group-charter-manager-api/src/services/MessageService.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,18 @@ export class MessageService {
108108
* Update a message
109109
*/
110110
async updateMessage(id: string, messageData: Partial<Message>): Promise<Message | null> {
111-
await this.messageRepository.update(id, messageData);
112-
return await this.getMessageById(id);
111+
// Get the current message, merge the data, and save it to trigger ORM events
112+
const currentMessage = await this.getMessageById(id);
113+
if (!currentMessage) {
114+
throw new Error("Message not found");
115+
}
116+
117+
// Merge the new data with the existing message
118+
Object.assign(currentMessage, messageData);
119+
120+
// Save the merged message to trigger ORM subscribers
121+
const updatedMessage = await this.messageRepository.save(currentMessage);
122+
return updatedMessage;
113123
}
114124

115125
/**
@@ -124,7 +134,16 @@ export class MessageService {
124134
* Archive a message
125135
*/
126136
async archiveMessage(id: string): Promise<Message | null> {
127-
await this.messageRepository.update(id, { isArchived: true });
128-
return await this.getMessageById(id);
137+
// Get the current message, set archived flag, and save it to trigger ORM events
138+
const currentMessage = await this.getMessageById(id);
139+
if (!currentMessage) {
140+
throw new Error("Message not found");
141+
}
142+
143+
currentMessage.isArchived = true;
144+
145+
// Save the updated message to trigger ORM subscribers
146+
const archivedMessage = await this.messageRepository.save(currentMessage);
147+
return archivedMessage;
129148
}
130149
}

platforms/group-charter-manager-api/src/services/UserService.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,18 @@ export class UserService {
9797
}
9898

9999
async updateUser(id: string, userData: Partial<User>): Promise<User | null> {
100-
await this.userRepository.update(id, userData);
101-
return await this.getUserById(id);
100+
// Get the current user, merge the data, and save it to trigger ORM events
101+
const currentUser = await this.getUserById(id);
102+
if (!currentUser) {
103+
throw new Error("User not found");
104+
}
105+
106+
// Merge the new data with the existing user
107+
Object.assign(currentUser, userData);
108+
109+
// Save the merged user to trigger ORM subscribers
110+
const updatedUser = await this.userRepository.save(currentUser);
111+
return updatedUser;
102112
}
103113

104114
async saveUser(user: User): Promise<User> {

0 commit comments

Comments
 (0)