CRM Field CRUD Service (lib/fields.ts)

mperkins0155/crm · database, Database / ORM, typescript, prisma, crm, fields, api

Functions to list, read, write, create, update, and archive custom fields for CRM entities via Prisma.

// Source: https://github.com/mperkins0155/crm | License: MIT | Copyright 2026 Comp AI
// Provided via justclaw.it.com; keep this notice with the code.
import { db } from "@crm/db";
import type { FieldEntity, FieldType } from "@crm/db/enums";
import {
	attachValues,
	type FieldDefinitionWithOptions,
	FieldValueError,
	fieldKeyFromLabel,
	type RecordField,
	recordColumn,
	type SerializedField,
	serializeField,
	usesOptions,
	writeValues,
} from "@crm/db/fields";

const WITH_OPTIONS = { options: { orderBy: { position: "asc" } } } as const;

export type { FieldEntity, FieldType, RecordField, SerializedField };

async function definitionsFor(
	entity: FieldEntity,
): Promise<FieldDefinitionWithOptions[]> {
	return db.fieldDefinition.findMany({
		where: { entity, archivedAt: null },
		include: 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key