Apply side effects of a completed operation. Param keys match schemas.ts.
(op: PendingOperation)
| 321 | |
| 322 | /** Apply side effects of a completed operation. Param keys match schemas.ts. */ |
| 323 | private applyOperationEffect(op: PendingOperation): void { |
| 324 | const { type, params } = op |
| 325 | |
| 326 | switch (type) { |
| 327 | case 'org:add-user': { |
| 328 | // Params: { org, user, role } — OrgAddUserParamsSchema |
| 329 | const org = params['org'] |
| 330 | const user = params['user'] |
| 331 | const role = (params['role'] as OrgRole) ?? 'developer' |
| 332 | if (org && user) { |
| 333 | const normalizedOrg = org.startsWith('@') ? org : `@${org}` |
| 334 | if (!this.state.orgs[normalizedOrg]) { |
| 335 | this.state.orgs[normalizedOrg] = { users: {}, teams: [], teamMembers: {} } |
| 336 | } |
| 337 | this.state.orgs[normalizedOrg].users[user] = role |
| 338 | } |
| 339 | break |
| 340 | } |
| 341 | case 'org:rm-user': { |
| 342 | // Params: { org, user } — OrgRemoveUserParamsSchema |
| 343 | const org = params['org'] |
| 344 | const user = params['user'] |
| 345 | if (org && user) { |
| 346 | const normalizedOrg = org.startsWith('@') ? org : `@${org}` |
| 347 | if (this.state.orgs[normalizedOrg]) { |
| 348 | delete this.state.orgs[normalizedOrg].users[user] |
| 349 | } |
| 350 | } |
| 351 | break |
| 352 | } |
| 353 | case 'org:set-role': { |
| 354 | // Params: { org, user, role } — reuses OrgAddUserParamsSchema |
| 355 | const org = params['org'] |
| 356 | const user = params['user'] |
| 357 | const role = params['role'] as OrgRole |
| 358 | if (org && user && role) { |
| 359 | const normalizedOrg = org.startsWith('@') ? org : `@${org}` |
| 360 | if (this.state.orgs[normalizedOrg]) { |
| 361 | this.state.orgs[normalizedOrg].users[user] = role |
| 362 | } |
| 363 | } |
| 364 | break |
| 365 | } |
| 366 | case 'team:create': { |
| 367 | // Params: { scopeTeam } — TeamCreateParamsSchema |
| 368 | const scopeTeam = params['scopeTeam'] |
| 369 | if (scopeTeam) { |
| 370 | const [scope, team] = scopeTeam.split(':') |
| 371 | if (scope && team) { |
| 372 | const normalizedScope = scope.startsWith('@') ? scope : `@${scope}` |
| 373 | if (!this.state.orgs[normalizedScope]) { |
| 374 | this.state.orgs[normalizedScope] = { users: {}, teams: [], teamMembers: {} } |
| 375 | } |
| 376 | if (!this.state.orgs[normalizedScope].teams.includes(team)) { |
| 377 | this.state.orgs[normalizedScope].teams.push(team) |
| 378 | } |
| 379 | this.state.orgs[normalizedScope].teamMembers[team] = [] |
| 380 | } |