This repository has been archived on 2024-09-23. You can view files and clone it, but cannot push or open issues or pull requests.
rocketchat-scim/Context.ts
2022-02-15 13:38:33 +01:00

52 lines
1.3 KiB
TypeScript

import {
IHttp,
IModify,
IPersistence,
IRead,
} from "@rocket.chat/apps-engine/definition/accessors";
import {
IApiEndpointInfo,
IApiRequest,
} from "@rocket.chat/apps-engine/definition/api";
import { EmptyRequestError } from "./errors/EmptyRequestError";
import { RcSdk } from "./rc-sdk/RcSdk";
export class Context {
public readonly rc: RcSdk;
public readonly request: IApiRequest;
public readonly endpoint: IApiEndpointInfo;
public readonly read: IRead;
public readonly modify: IModify;
public readonly http: IHttp;
public readonly persis: IPersistence;
constructor(
request: IApiRequest,
endpoint: IApiEndpointInfo,
read: IRead,
modify: IModify,
http: IHttp,
persis: IPersistence,
) {
this.rc = new RcSdk(http, read);
this.request = request;
this.endpoint = endpoint;
this.read = read;
this.modify = modify;
this.http = http;
this.persis = persis;
}
public id(): string {
return this.request.params.id;
}
public content(): any {
if (
!this.request.content ||
Object.keys(this.request.content).length === 0
) {
throw new EmptyRequestError();
}
return this.request.content;
}
}