mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
* feat: add Api and Session contexts * feat(web): add machinery/new-session * feat(web): add servers page * chore(web): AppRouter spacing/ordering * feat(web): add picker, missing update-roles call for now * feat(web): add picker saves * chore: add roleTransactions tests * feat(web): add auth/login
30 lines
782 B
TypeScript
30 lines
782 B
TypeScript
import { Role, RoleTransaction, TransactionType } from '@roleypoly/types';
|
|
|
|
export const makeRoleTransactions = (
|
|
oldRoles: Role['id'][],
|
|
newRoles: Role['id'][]
|
|
): RoleTransaction[] => {
|
|
const transactions: RoleTransaction[] = [];
|
|
|
|
// Removes: old roles not in new roles
|
|
for (let oldID of oldRoles) {
|
|
if (!newRoles.includes(oldID)) {
|
|
transactions.push({
|
|
id: oldID,
|
|
action: TransactionType.Remove,
|
|
});
|
|
}
|
|
}
|
|
|
|
// Adds: new roles not in old roles
|
|
for (let newID of newRoles) {
|
|
if (!oldRoles.includes(newID)) {
|
|
transactions.push({
|
|
id: newID,
|
|
action: TransactionType.Add,
|
|
});
|
|
}
|
|
}
|
|
|
|
return transactions;
|
|
};
|