Click here to Skip to main content
15,887,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SyntaxError: Unexpected token ':'

What I have tried:

static get aceessList() {
  return [ "Admin":
  { "/api/masters/wing/manageWing",
  "/api/user/save-member",
  "/api/user/changepassword"
 },
 "Data Entry Operator":
 { "/api/admin/upload-data",
 "/api/admin/upload-income-data",
 "/api/masters/purchaserequisitionheader/managepurchaserequisitionheader"
}];
}
Posted
Updated 26-Mar-23 23:58pm
v4
Comments
Member 15627495 26-Mar-23 15:15pm    
there are a lot of functions for Array,

"Array.of()" create an array from any arrays like structures.
return Array.of(["Admin" , ["/api/masters/wing/manageWing"]]) ;


the : as separator belong to JSON, use "," instead.
Member 15926609 27-Mar-23 2:16am    
I have 4 role based on role user can access only purticular api.
static get aceessList() {
return [ "Admin":
{ "/api/masters/wing/manageWing",
"/api/user/save-member",
"/api/user/changepassword"
},
"Data Entry Operator":
{ "/api/admin/upload-data",
"/api/admin/upload-income-data",
"/api/masters/purchaserequisitionheader/managepurchaserequisitionheader"
}];
}

can please tell me how array should be.

Believe the key must be a valid identifier.
JavaScript
// for quick check, removed static 
function getaceessList() {
// NOT this
// return [{"Admin" : ["/api/masters/wing/manageWing"]}];
// TRY this
return {["Admin"] : "/api/masters/wing/manageWing"};
// Use like this
// console.log(getaceessList().Admin); output => "/api/masters/wing/manageWing"
}
Refer: Object initializer - JavaScript | MDN[^]

PS: I am assuming, given method is marked static, it is accessed via a class only. Refer[^].
 
Share this answer
 
I think you need to rethink how you're structuring this access list. The semantics you're using don't fit together with what it is you're trying to accomplish.

[ A, B, C ] defines an array, which means it can contain elements but you cannot specify the A: B relationship. It's not designed for that.

{ A: B, C: D } defines an object, which means you can define the A: B relationship, and arrays must be included as a child property.

From your example you probably need to choose whether you want one of the following:

// =====
// Object-based where the key is the role name
// -----

// Example:
const accessList = {
  "Admin": [ "/api/..", "/api/.." ],
  "Data Entry Operator": [ "/api/..", "/api/.." ]
}

// Accessing:
const endpoints = accessList.Admin;
const endpoints = accessList["Data Entry Operator"];

// =====
// Array based where the role name and access points are properties
// -----

// Example:
const accessList = [
  { "Name": "Admin", "Endpoints": [ "/api/.." ] },
  { "Name": "Data Entry Operator", "Endpoints": [ "/api/.."] }
]

// Accessing:
const admin = accessList.filter(x => x.Name == "Admin")[0];
const endpoints = admin.Endpoints;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900