Controllers

Families - Controller

List and retrieve `Family` models.

To implement the Families controller, you need to implement 2 API endpoints, we will use these endpoints to fetch families from your system.

Prerequisites

Family Model

A group of products or services.

Required

SDK

import { Integrator } from '@churnkey/sdk'
import { Context } from '../Context'
import { Family } from '../models/Family'

export const Families = Integrator.Families.config({
    ctx: Context,
    async retrieve(ctx, options) {
        const yourFamily = await ctx.db.findFamily(options.id)
        return new Family(yourFamily)
    },
    async list(ctx, options) {
        const yourFamilies = await ctx.db.listFamilys({
            limit: options.limit,
            offset: options.cursor // the value you pass as `next` below
        })
        return {
            data: yourFamilies.map(family => new Family(family)),
            // pass the next cursor if there are more items
            next: yourFamilies.length === options.limit ? offset + limit : undefined
        }
    }
})

Endpoints

Retrieve Required

GET /churnkey/families/:id

This endpoint fetches Family by its id. Usually, implementation will include finding a family in your database and mapping it to the Family model.

List Required

GET /churnkey/families

This endpoint fetches a list of families from your database. You should find families in your database (with pagination), map them to the Family model and return a paginated list.

Learn more about pagination.

Webhooks

Coming soon.