MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / processSingleRead

Method processSingleRead

packages/server/src/api/rest/index.ts:807–833  ·  view source on GitHub ↗
(
        client: ClientContract<Schema>,
        type: string,
        resourceId: string,
        query: Record<string, string | string[]> | undefined,
    )

Source from the content-addressed store, hash-verified

805 }
806
807 private async processSingleRead(
808 client: ClientContract<Schema>,
809 type: string,
810 resourceId: string,
811 query: Record<string, string | string[]> | undefined,
812 ): Promise<Response> {
813 const typeInfo = this.getModelInfo(type);
814 if (!typeInfo) {
815 return this.makeUnsupportedModelError(type);
816 }
817
818 const { args, include, error } = this.buildSingleReadArgs(type, query);
819 if (error) return error;
820
821 args.where = this.makeIdFilter(typeInfo.idFields, resourceId);
822
823 const entity = await (client as any)[type].findUnique(args);
824
825 if (entity) {
826 return {
827 status: 200,
828 body: await this.serializeItems(type, entity, { include }),
829 };
830 } else {
831 return this.makeError('notFound');
832 }
833 }
834
835 private async processFetchRelated(
836 client: ClientContract<Schema>,

Callers 1

handleRequestMethod · 0.95

Calls 6

getModelInfoMethod · 0.95
buildSingleReadArgsMethod · 0.95
makeIdFilterMethod · 0.95
serializeItemsMethod · 0.95
makeErrorMethod · 0.95

Tested by

no test coverage detected