Skip to content

Commit

Permalink
Disable sync flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jschr committed Dec 22, 2024
1 parent b0af16f commit e08afc5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 5 additions & 2 deletions api/src/handlers/scheduleSyncUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ if (!runSyncUsersQueueUrl) {

export default withScheduledHandler(async () => {
const users = await UserModel.all();
console.info(`Found '${users.length}' users to sync`);
await Promise.all(users.map(createSyncUserJob));

const usersToSync = users.filter((user) => !user.disabled);
console.info(`Syncing ${usersToSync.length}/${users.length} users`);

await Promise.all(usersToSync.map(createSyncUserJob));
});

const createSyncUserJob = async (user: UserModel) => {
Expand Down
20 changes: 14 additions & 6 deletions api/src/models/UserModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface User {
lastLoginAt: string;
createdAt: string;
sharedRegions: string[];
disabled?: boolean;
}

const isNotNullOrUndefined = <T>(value: T | null | undefined): value is T => {
Expand Down Expand Up @@ -41,7 +42,7 @@ export default class UserModel {
id: string;
}>,
): Promise<Array<UserModel | null>> {
const requestKeys = items.filter(i => i.id).map(this.toAttributeMap);
const requestKeys = items.filter((i) => i.id).map(this.toAttributeMap);
if (requestKeys.length === 0) return [];

const params: DynamoDB.BatchGetItemInput = {
Expand All @@ -64,11 +65,11 @@ export default class UserModel {
}

const UserModels = tableResults.map(
attrMap => new UserModel(this.fromAttributeMap(attrMap)),
(attrMap) => new UserModel(this.fromAttributeMap(attrMap)),
);

return items.map(
item => UserModels.find(um => um.id === item.id) ?? null,
(item) => UserModels.find((um) => um.id === item.id) ?? null,
);
} catch (err) {
throw new Error(
Expand Down Expand Up @@ -96,7 +97,7 @@ export default class UserModel {
}

const users = res.Items.map(
attrMap => new UserModel(this.fromAttributeMap(attrMap)),
(attrMap) => new UserModel(this.fromAttributeMap(attrMap)),
);

return [users, res.LastEvaluatedKey];
Expand Down Expand Up @@ -138,9 +139,10 @@ export default class UserModel {
if (user.createdAt !== undefined) attrMap.createdAt = { S: user.createdAt };
if (user.sharedRegions !== undefined) {
attrMap.sharedRegions = attrMap.sharedRegions = {
L: user.sharedRegions.map(regionId => ({ S: regionId })),
L: user.sharedRegions.map((regionId) => ({ S: regionId })),
};
}
if (user.disabled !== undefined) attrMap.disabled = { BOOL: user.disabled };

return attrMap;
}
Expand All @@ -159,9 +161,10 @@ export default class UserModel {
expiresAt: attrMap.expiresAt?.S,
lastLoginAt: attrMap.lastLoginAt?.S,
createdAt: attrMap.createdAt?.S,
sharedRegions: attrMap.sharedRegions?.L?.map(i => i.S).filter(
sharedRegions: attrMap.sharedRegions?.L?.map((i) => i.S).filter(
isNotNullOrUndefined,
),
disabled: attrMap.disabled?.BOOL ?? false,
};
}

Expand Down Expand Up @@ -223,13 +226,18 @@ export default class UserModel {
return this.attrs.sharedRegions ?? [];
}

get disabled() {
return this.attrs.disabled ?? false;
}

public toJSON() {
return {
id: this.id,
username: this.username,
profilePictureUrl: this.profilePictureUrl,
createdAt: this.createdAt,
sharedRegions: this.sharedRegions,
disabled: this.disabled,
};
}
}
Binary file added app-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e08afc5

Please sign in to comment.