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/src/endpoints/Context.ts
2022-02-15 15:53:18 +01:00

55 lines
1.4 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";
import { Store } from "../store/Store";
export class Context {
public readonly rc: RcSdk;
public readonly store: Store;
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.store = new Store(read, persis);
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;
}
}