add permission brother
This commit is contained in:
parent
2cb7a9ab07
commit
c6fabbcf16
2 changed files with 64 additions and 49 deletions
|
|
@ -1551,7 +1551,7 @@ export class DevelopmentController extends Controller {
|
||||||
if (!development) {
|
if (!development) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
||||||
}
|
}
|
||||||
Object.assign(development, { ...requestBody});
|
Object.assign(development, { ...requestBody });
|
||||||
development.lastUpdateUserId = request.user.sub;
|
development.lastUpdateUserId = request.user.sub;
|
||||||
development.lastUpdateFullName = request.user.name;
|
development.lastUpdateFullName = request.user.name;
|
||||||
development.lastUpdatedAt = new Date();
|
development.lastUpdatedAt = new Date();
|
||||||
|
|
@ -2085,7 +2085,7 @@ export class DevelopmentController extends Controller {
|
||||||
_data.child1 != undefined && _data.child1 != null
|
_data.child1 != undefined && _data.child1 != null
|
||||||
? _data.child1[0] != null
|
? _data.child1[0] != null
|
||||||
? `development.child1DnaId IN (:...child1)`
|
? `development.child1DnaId IN (:...child1)`
|
||||||
: `development.child1DnaId is null`
|
: `development.child1DnaId is ${_data.privilege == "PARENT" ? "not null" : "null"}`
|
||||||
: "1=1",
|
: "1=1",
|
||||||
{
|
{
|
||||||
child1: _data.child1,
|
child1: _data.child1,
|
||||||
|
|
@ -2130,19 +2130,15 @@ export class DevelopmentController extends Controller {
|
||||||
"development.child2",
|
"development.child2",
|
||||||
"development.child3",
|
"development.child3",
|
||||||
"development.child4",
|
"development.child4",
|
||||||
])
|
]);
|
||||||
|
|
||||||
if (sortBy) {
|
if (sortBy) {
|
||||||
query = query.orderBy(
|
query = query.orderBy(`development.${sortBy}`, descending ? "DESC" : "ASC");
|
||||||
`development.${sortBy}`,
|
} else {
|
||||||
descending ? "DESC" : "ASC"
|
query = query.orderBy("development.year", "DESC").addOrderBy("development.createdAt", "DESC");
|
||||||
);
|
}
|
||||||
}else{
|
|
||||||
query = query.orderBy("development.year", "DESC")
|
|
||||||
.addOrderBy("development.createdAt", "DESC")
|
|
||||||
}
|
|
||||||
|
|
||||||
const [development, total] = await query
|
const [development, total] = await query
|
||||||
.skip((page - 1) * pageSize)
|
.skip((page - 1) * pageSize)
|
||||||
.take(pageSize)
|
.take(pageSize)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
|
|
@ -2632,12 +2628,13 @@ export class DevelopmentController extends Controller {
|
||||||
});
|
});
|
||||||
|
|
||||||
const developmentAddresss = await this.developmentAddresssRepository.find({
|
const developmentAddresss = await this.developmentAddresssRepository.find({
|
||||||
where: { developmentId: id}
|
where: { developmentId: id },
|
||||||
})
|
});
|
||||||
|
|
||||||
const places = developmentAddresss
|
const places = developmentAddresss
|
||||||
.map(addr =>
|
.map(
|
||||||
`- ${addr.address}, ${addr.addressType === "IN_COUNTRY" ? addr.provinceName : addr.country} (${addr.addressType === "IN_COUNTRY" ? "ภายในประเทศ" : "ภายนอกประเทศ"})`
|
(addr) =>
|
||||||
|
`- ${addr.address}, ${addr.addressType === "IN_COUNTRY" ? addr.provinceName : addr.country} (${addr.addressType === "IN_COUNTRY" ? "ภายในประเทศ" : "ภายนอกประเทศ"})`,
|
||||||
)
|
)
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
@ -2768,7 +2765,7 @@ export class DevelopmentController extends Controller {
|
||||||
techniqueActuals.length > 0 && dev20Lists.some((item) => techniqueActuals.includes(item));
|
techniqueActuals.length > 0 && dev20Lists.some((item) => techniqueActuals.includes(item));
|
||||||
isDevelopment10 =
|
isDevelopment10 =
|
||||||
techniqueActuals.length > 0 && dev10Lists.some((item) => techniqueActuals.includes(item));
|
techniqueActuals.length > 0 && dev10Lists.some((item) => techniqueActuals.includes(item));
|
||||||
|
|
||||||
if (x.type == "OFFICER") {
|
if (x.type == "OFFICER") {
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.PostData(request, "/org/profile/development", {
|
.PostData(request, "/org/profile/development", {
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,15 @@ class CheckAuth {
|
||||||
child4: null,
|
child4: null,
|
||||||
privilege: "ROOT",
|
privilege: "ROOT",
|
||||||
};
|
};
|
||||||
|
} else if (privilege == "PARENT") {
|
||||||
|
data = {
|
||||||
|
root: [x.orgRootId],
|
||||||
|
child1: [null],
|
||||||
|
child2: null,
|
||||||
|
child3: null,
|
||||||
|
child4: null,
|
||||||
|
privilege: "PARENT",
|
||||||
|
};
|
||||||
} else if (privilege == "CHILD") {
|
} else if (privilege == "CHILD") {
|
||||||
data = {
|
data = {
|
||||||
root: node >= 0 ? [x.orgRootId] : null,
|
root: node >= 0 ? [x.orgRootId] : null,
|
||||||
|
|
@ -103,6 +112,15 @@ class CheckAuth {
|
||||||
child4: node >= 4 ? [x.orgChild4Id] : null,
|
child4: node >= 4 ? [x.orgChild4Id] : null,
|
||||||
privilege: "CHILD",
|
privilege: "CHILD",
|
||||||
};
|
};
|
||||||
|
} else if (privilege == "BROTHER") {
|
||||||
|
data = {
|
||||||
|
// root: node >= 0 ? [x.orgRootId] : null,
|
||||||
|
root: node >= 0 ? [x.orgRootId] : null,
|
||||||
|
child1: node >= 2 ? [x.orgChild1Id] : null,
|
||||||
|
child2: node >= 3 ? [x.orgChild2Id] : null,
|
||||||
|
child3: node >= 4 ? [x.orgChild3Id] : null,
|
||||||
|
privilege: "BROTHER",
|
||||||
|
};
|
||||||
} else if (privilege == "NORMAL") {
|
} else if (privilege == "NORMAL") {
|
||||||
data = {
|
data = {
|
||||||
root: [x.orgRootId],
|
root: [x.orgRootId],
|
||||||
|
|
@ -185,38 +203,38 @@ class CheckAuth {
|
||||||
}
|
}
|
||||||
public async checkOrg(token: any, keycloakId: string) {
|
public async checkOrg(token: any, keycloakId: string) {
|
||||||
const redisClient = await this.redis.createClient({
|
const redisClient = await this.redis.createClient({
|
||||||
host: process.env.REDIS_HOST,
|
host: process.env.REDIS_HOST,
|
||||||
port: process.env.REDIS_PORT,
|
port: process.env.REDIS_PORT,
|
||||||
})
|
});
|
||||||
const getAsync = promisify(redisClient.get).bind(redisClient)
|
const getAsync = promisify(redisClient.get).bind(redisClient);
|
||||||
try {
|
try {
|
||||||
let reply = await getAsync("org_" + keycloakId)
|
let reply = await getAsync("org_" + keycloakId);
|
||||||
if (reply != null) {
|
if (reply != null) {
|
||||||
reply = JSON.parse(reply)
|
reply = JSON.parse(reply);
|
||||||
} else {
|
} else {
|
||||||
if (!keycloakId) throw new Error("No KeycloakId provided")
|
if (!keycloakId) throw new Error("No KeycloakId provided");
|
||||||
const x = await new CallAPI().GetData(
|
const x = await new CallAPI().GetData(
|
||||||
{
|
{
|
||||||
headers: { authorization: token },
|
headers: { authorization: token },
|
||||||
},
|
},
|
||||||
`/org/permission/checkOrg/${keycloakId}`,
|
`/org/permission/checkOrg/${keycloakId}`,
|
||||||
false
|
false,
|
||||||
)
|
);
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
orgRootId: x.orgRootId,
|
orgRootId: x.orgRootId,
|
||||||
orgChild1Id: x.orgChild1Id,
|
orgChild1Id: x.orgChild1Id,
|
||||||
orgChild2Id: x.orgChild2Id,
|
orgChild2Id: x.orgChild2Id,
|
||||||
orgChild3Id: x.orgChild3Id,
|
orgChild3Id: x.orgChild3Id,
|
||||||
orgChild4Id: x.orgChild4Id,
|
orgChild4Id: x.orgChild4Id,
|
||||||
}
|
};
|
||||||
|
|
||||||
return data
|
return data;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error calling API:", error)
|
console.error("Error calling API:", error);
|
||||||
throw error
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async PermissionCreate(req: RequestWithUser, system: string) {
|
public async PermissionCreate(req: RequestWithUser, system: string) {
|
||||||
return await this.Permission(req, system, "CREATE");
|
return await this.Permission(req, system, "CREATE");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue