2023-08-14 11:00:46 +00:00
|
|
|
import ProjectSsoService, {
|
2024-06-14 11:09:53 +00:00
|
|
|
Service as ProjectSsoServiceType,
|
|
|
|
} from "../Services/ProjectSsoService";
|
|
|
|
import { ExpressRequest, ExpressResponse } from "../Utils/Express";
|
|
|
|
import Response from "../Utils/Response";
|
|
|
|
import BaseAPI from "./BaseAPI";
|
|
|
|
import { LIMIT_PER_PROJECT } from "Common/Types/Database/LimitMax";
|
|
|
|
import BadDataException from "Common/Types/Exception/BadDataException";
|
|
|
|
import ObjectID from "Common/Types/ObjectID";
|
|
|
|
import PositiveNumber from "Common/Types/PositiveNumber";
|
|
|
|
import ProjectSSO from "Model/Models/ProjectSso";
|
2023-08-14 11:00:46 +00:00
|
|
|
|
|
|
|
export default class ProjectSsoAPI extends BaseAPI<
|
2024-06-14 11:09:53 +00:00
|
|
|
ProjectSSO,
|
|
|
|
ProjectSsoServiceType
|
2023-08-14 11:00:46 +00:00
|
|
|
> {
|
2024-06-14 11:09:53 +00:00
|
|
|
public constructor() {
|
|
|
|
super(ProjectSSO, ProjectSsoService);
|
2023-08-14 11:00:46 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
// SSO Fetch API
|
|
|
|
this.router.post(
|
|
|
|
`${new this.entityType()
|
|
|
|
.getCrudApiPath()
|
|
|
|
?.toString()}/:projectId/sso-list`,
|
|
|
|
async (req: ExpressRequest, res: ExpressResponse) => {
|
|
|
|
const projectId: ObjectID = new ObjectID(
|
|
|
|
req.params["projectId"] as string,
|
|
|
|
);
|
2023-08-14 11:00:46 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
if (!projectId) {
|
|
|
|
return Response.sendErrorResponse(
|
|
|
|
req,
|
|
|
|
res,
|
|
|
|
new BadDataException("Invalid project id."),
|
|
|
|
);
|
|
|
|
}
|
2023-08-14 11:00:46 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
const sso: Array<ProjectSSO> = await this.service.findBy({
|
|
|
|
query: {
|
|
|
|
projectId: projectId,
|
|
|
|
isEnabled: true,
|
|
|
|
},
|
|
|
|
limit: LIMIT_PER_PROJECT,
|
|
|
|
skip: 0,
|
|
|
|
select: {
|
|
|
|
name: true,
|
|
|
|
description: true,
|
|
|
|
_id: true,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
isRoot: true,
|
|
|
|
},
|
|
|
|
});
|
2023-08-14 11:00:46 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
return Response.sendEntityArrayResponse(
|
|
|
|
req,
|
|
|
|
res,
|
|
|
|
sso,
|
|
|
|
new PositiveNumber(sso.length),
|
|
|
|
ProjectSSO,
|
2023-08-14 11:00:46 +00:00
|
|
|
);
|
2024-06-14 11:09:53 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2023-08-14 11:00:46 +00:00
|
|
|
}
|