52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { HttpStatusCode } from "@rocket.chat/apps-engine/definition/accessors";
|
|
import { IApiResponse } from "@rocket.chat/apps-engine/definition/api";
|
|
import { Context } from "./Context";
|
|
import { SCIMUser } from "./scim/User";
|
|
import { IScimEndpoint, ScimEndpoint } from "./ScimEndpoint";
|
|
|
|
export class UserEndpoint extends ScimEndpoint implements IScimEndpoint {
|
|
public path = "Users/:id";
|
|
|
|
public async _get(ctx: Context): Promise<IApiResponse> {
|
|
const o = await ctx.rc.user.info(ctx.id());
|
|
this.handleError(o);
|
|
const user = SCIMUser.fromRC(o.user);
|
|
return this.success(user);
|
|
}
|
|
|
|
public async _put(ctx: Context): Promise<IApiResponse> {
|
|
const o = await ctx.rc.user.update(
|
|
this.scimToUserUpdate(ctx.id(), SCIMUser.fromPlain(ctx.content())),
|
|
);
|
|
this.handleError(o);
|
|
const user = SCIMUser.fromRC(o.user);
|
|
return this.success(user);
|
|
}
|
|
|
|
public async _delete(ctx: Context): Promise<IApiResponse> {
|
|
const o = await ctx.rc.user.delete({
|
|
userId: ctx.id(),
|
|
confirmRelinquish: true,
|
|
});
|
|
this.handleError(o);
|
|
return this.response({
|
|
status: HttpStatusCode.NO_CONTENT,
|
|
});
|
|
}
|
|
|
|
private scimToUserUpdate(userId: string, user: SCIMUser): IUserUpdate {
|
|
return {
|
|
userId,
|
|
data: {
|
|
email: user.getEmail(),
|
|
name: user.displayName,
|
|
username: user.userName,
|
|
active: user.active,
|
|
verified: true,
|
|
customFields: {
|
|
scimExternalId: user.externalId,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
}
|