Skip to content

Commit

Permalink
chore: auto generate NOTIFICATION_TYPE_CODE_MAP from NOTIFICATION_TYP…
Browse files Browse the repository at this point in the history
…E_MAP
  • Loading branch information
laminne committed Dec 17, 2024
1 parent 7497cfd commit 7ff3fa9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
21 changes: 10 additions & 11 deletions pkg/notification/adaptor/repository/dummy/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,20 @@ export class InMemoryNotificationRepository implements NotificationRepository {
const cursor = Option.unwrap(filter.cursor);

switch (cursor.type) {
case 'after':
return (() => {
const afterIndex = res
.reverse()
.findIndex((n) => n.getID() === cursor.id);
return Result.ok(
res.slice(afterIndex + 1, afterIndex + limit).reverse(),
);
})();

case 'before':
case 'after': {
const afterIndex = res
.reverse()
.findIndex((n) => n.getID() === cursor.id);
return Result.ok(
res.slice(afterIndex + 1, afterIndex + limit).reverse(),
);
}
case 'before': {
return (() => {
const beforeIndex = res.findIndex((n) => n.getID() === cursor.id);
return Result.ok(res.slice(beforeIndex + 1, beforeIndex + 1 + limit));
})();
}
}
}

Expand Down
17 changes: 9 additions & 8 deletions pkg/notification/adaptor/repository/prisma/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@ export class PrismaNotificationRepository implements NotificationRepository {
private readonly NOTIFICATION_TYPE_CODE_MAP: Record<

Check warning on line 38 in pkg/notification/adaptor/repository/prisma/notification.ts

View check run for this annotation

Codecov / codecov/patch

pkg/notification/adaptor/repository/prisma/notification.ts#L30-L38

Added lines #L30 - L38 were not covered by tests
number,
NotificationType
> = {
1: 'followed',
2: 'followRequested',
3: 'followAccepted',
4: 'mentioned',
5: 'renoted',
6: 'reacted',
} as const;
> = [];

Check warning on line 41 in pkg/notification/adaptor/repository/prisma/notification.ts

View check run for this annotation

Codecov / codecov/patch

pkg/notification/adaptor/repository/prisma/notification.ts#L41

Added line #L41 was not covered by tests

constructor(prisma: PrismaClient) {
this.prisma = prisma;

Check warning on line 44 in pkg/notification/adaptor/repository/prisma/notification.ts

View check run for this annotation

Codecov / codecov/patch

pkg/notification/adaptor/repository/prisma/notification.ts#L43-L44

Added lines #L43 - L44 were not covered by tests

for (const [k, v] of Object.entries(this.NOTIFICATION_TYPE_MAP)) {
if (v in this.NOTIFICATION_TYPE_CODE_MAP)
throw new Error('Duplicate value');

Check warning on line 48 in pkg/notification/adaptor/repository/prisma/notification.ts

View check run for this annotation

Codecov / codecov/patch

pkg/notification/adaptor/repository/prisma/notification.ts#L46-L48

Added lines #L46 - L48 were not covered by tests

this.NOTIFICATION_TYPE_CODE_MAP[v] = k as NotificationType;
}
Object.freeze(this.NOTIFICATION_TYPE_CODE_MAP);
}

Check warning on line 53 in pkg/notification/adaptor/repository/prisma/notification.ts

View check run for this annotation

Codecov / codecov/patch

pkg/notification/adaptor/repository/prisma/notification.ts#L50-L53

Added lines #L50 - L53 were not covered by tests

private serialize(
Expand Down

0 comments on commit 7ff3fa9

Please sign in to comment.