(input: {
userId: string;
itemType: 'group' | 'page';
itemId: string;
dataAbstraction: DataAbstraction<typeof dataHashes>;
dtrx?: DataTransaction;
})
| 3 | import { pull } from 'lodash'; |
| 4 | |
| 5 | export async function bumpRecentItem(input: { |
| 6 | userId: string; |
| 7 | |
| 8 | itemType: 'group' | 'page'; |
| 9 | itemId: string; |
| 10 | |
| 11 | dataAbstraction: DataAbstraction<typeof dataHashes>; |
| 12 | dtrx?: DataTransaction; |
| 13 | }) { |
| 14 | const recentItemIds: string[] = await input.dataAbstraction.hget( |
| 15 | 'user', |
| 16 | input.userId, |
| 17 | `recent-${input.itemType}-ids`, |
| 18 | ); |
| 19 | |
| 20 | // Prepend item ID to recent item IDs |
| 21 | |
| 22 | pull(recentItemIds, input.itemId); |
| 23 | recentItemIds.splice(0, 0, input.itemId); |
| 24 | |
| 25 | while (recentItemIds.length > 50) { |
| 26 | recentItemIds.pop(); |
| 27 | } |
| 28 | |
| 29 | // Update recent item IDs |
| 30 | |
| 31 | await input.dataAbstraction.patch( |
| 32 | 'user', |
| 33 | input.userId, |
| 34 | { [`recent_${input.itemType}_ids`]: recentItemIds }, |
| 35 | { dtrx: input.dtrx }, |
| 36 | ); |
| 37 | } |
no test coverage detected