Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

202
Vistas
TypeScript Data structure for indexed actions table

I have a series of roles with ascending permissions. I also have series of issue states. I expect both of these to be represented as TypeScript enums.

I wish to provide a series of available actions, for different roles, for issues in different states: enter image description here

I have a couple of related challenges.

  1. I wish to have a data structure where the role/issue-state are indexed by TS enums
  2. I wish to be able to store data in the structure in a legible manner (for easy review by a domain expert), like below
actions[engineer][newReqest] = ["Claim"]
actions[engineer][liveRequest] = ["Submit for review"]
  1. When determining the actions for the current role ("Manager") I should be able to retrieve the inferred actions for the lower roles too ("Engineer" and "Team Lead")

Can anybody point me to the TypeScript object type that best suits the above scenario?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I've attempted a solution in a playground. I supports the domain-expert-legible assignment, but I have some remaining TS errors. It could probably be improved...

enum Roles {
  Engineer,
  TeamLeader,
  Manager
}

enum IssueStates {
  New,
  Live,
  Closed
}

const actions = []
actions[IssueStates.New] = []
actions[IssueStates.Live] = []
actions[IssueStates.Closed] = []
actions[IssueStates.New][Roles.Engineer] = ["Claim"]
actions[IssueStates.Live][Roles.Engineer] = ["Submit"]
actions[IssueStates.Live][Roles.TeamLeader] = ["Accept", "Reject"]
actions[IssueStates.Closed][Roles.Manager] = ["ReOpen"]

const actionsFor = (tblActions: any, state: IssueStates, role: Roles): Array<String> => {
  const forState = tblActions[state]
  const actions = forState.filter((element: any, index: number) => index <= role)
  return actions.flat(2) || []
}

console.log("Team leader for live issue", actionsFor(actions, IssueStates.Live, Roles.TeamLeader))
console.log("Team leader for closed issue", actionsFor(actions, IssueStates.Closed, Roles.TeamLeader))
console.log("Manager for closed issue", actionsFor(actions, IssueStates.Closed, Roles.Manager))

let summary = ""
for(let state in IssueStates) {
  if(!isNaN(+state)) {
    for(let role in Roles) {
      if(!isNaN(+role)) {
        summary += state + ", " + role  + ", " + actionsFor(actions, state, role) + "\n"
      }
    }
  }
}
console.log("Summary",  "\n", summary)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda