fix: User updates are not synced between clients (#6490)

* Add Model.changeset method to get minified changes since last update

* fix: Handle arrays

* Add changes column, types

* test
This commit is contained in:
Tom Moor
2024-02-04 10:36:43 -08:00
committed by GitHub
parent 06ab5e5f44
commit 234613580d
11 changed files with 295 additions and 55 deletions

View File

@@ -226,17 +226,17 @@ router.post(
user.setPreference(key, preferences[key] as boolean);
}
}
await user.save({ transaction });
await Event.create(
await Event.createFromContext(
ctx,
{
name: "users.update",
actorId: user.id,
userId: user.id,
teamId: user.teamId,
ip: ctx.request.ip,
changes: user.changeset,
},
{ transaction }
);
await user.save({ transaction });
ctx.body = {
data: presentUser(user, {
@@ -547,9 +547,18 @@ router.post(
async (ctx: APIContext<T.UsersNotificationsSubscribeReq>) => {
const { eventType } = ctx.input.body;
const { transaction } = ctx.state;
const { user } = ctx.state.auth;
user.setNotificationEventType(eventType, true);
await Event.createFromContext(
ctx,
{
name: "users.update",
userId: user.id,
changes: user.changeset,
},
{ transaction }
);
await user.save({ transaction });
ctx.body = {
@@ -566,9 +575,18 @@ router.post(
async (ctx: APIContext<T.UsersNotificationsUnsubscribeReq>) => {
const { eventType } = ctx.input.body;
const { transaction } = ctx.state;
const { user } = ctx.state.auth;
user.setNotificationEventType(eventType, false);
await Event.createFromContext(
ctx,
{
name: "users.update",
userId: user.id,
changes: user.changeset,
},
{ transaction }
);
await user.save({ transaction });
ctx.body = {