All files / json-crdt-server/src/routes/block/methods get.ts

100% Statements 11/11
100% Branches 0/0
100% Functions 3/3
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28  4x     4x 4x 93x 93x             93x   93x         93x 90x 63x 63x      
import type {ResolveType} from '@jsonjoy.com/json-type';
import {BlockIdRef, BlockRef} from '../schema';
import type {RouteDeps, Router, RouterBase} from '../../types';
 
export const get =
  ({t, services}: RouteDeps) =>
  <R extends RouterBase>(r: Router<R>) => {
    const Request = t.Object(
      t.Key('id', BlockIdRef).options({
        title: 'Block ID',
        description: 'The ID of the block to retrieve.',
      }),
    );
 
    const Response = t.Object(t.Key('block', BlockRef));
 
    const Func = t.Function(Request, Response).options({
      title: 'Read Block',
      intro: 'Retrieves a block by ID.',
    });
 
    return r.add('block.get', Func, async ({id}) => {
      const {block} = await services.blocks.get(id);
      const response: ResolveType<typeof Response> = {block};
      return response;
    });
  };