All files / realm/blong-party/meta/model partyConsentModel.ts

100% Statements 138/138
100% Branches 2/2
100% Functions 1/1
100% Lines 138/138

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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 1391x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x  
import {model} from '@feasibleone/blong';
 
/**
 * partyConsentModel — consent records (Browse/New/Open).
 *
 * A consent belongs to a person (`consent --belongsTo--> person`, managed as a
 * pivot by the generic CRUD) and is one of the records the record-level ACL
 * matrix probes: `meta/db/db.ts` declares the table `acl: {mode: 'explicit'}`, so
 * the model page and the matrix describe the same access — a rule or nothing.
 */
export default model(
    () =>
        async function partyConsentModel() {
            return {
                subject: 'party',
                object: 'consent',
                objectTitle: 'Consent',
                public: true,
                nameField: 'consent.consentName',
 
                schema: {
                    properties: {
                        consent: {
                            properties: {
                                consentName: {title: 'Name'},
                                consentType: {
                                    title: 'Type',
                                    widget: {
                                        options: [
                                            {value: 'marketing', label: 'Marketing'},
                                            {value: 'research', label: 'Research'},
                                            {value: 'profiling', label: 'Profiling'},
                                        ],
                                    },
                                },
                                isGranted: {title: 'Granted', type: 'boolean'},
                                notes: {title: 'Notes'},
                                // server schema defined
                                // consentId: {},
                            },
                            widget: {
                                columns: ['consentName', 'consentType', 'isGranted'],
                            },
                        },
                        person: {
                            // The owning person.  The `belongsTo` edge is declared
                            // in `meta/db/db.ts`, so the pivot is maintained by the
                            // generic CRUD.
                            title: '',
                            items: {
                                properties: {
                                    firstName: {title: 'First Name'},
                                    lastName: {title: 'Last Name'},
                                },
                            },
                            widget: {
                                type: 'table',
                                columns: ['firstName', 'lastName'],
                            },
                        },
                    },
                },
 
                cards: {
                    browse: {
                        label: 'Consents',
                        widgets: ['consent'],
                    },
                    details: {
                        label: 'Consent Details',
                        widgets: [
                            'consent.consentName',
                            'consent.consentType',
                            'consent.isGranted',
                            'consent.notes',
                        ],
                    },
                    personCard: {
                        label: 'Person',
                        widgets: ['person'],
                    },
                },
 
                layouts: {
                    edit: [['details']],
                    editThumbIndex: {
                        orientation: 'left',
                        items: [
                            {
                                id: 'details',
                                label: 'Consent Details',
                                icon: 'pi pi-check-square',
                                widgets: ['details'],
                            },
                            {
                                id: 'person',
                                label: 'Person',
                                icon: 'pi pi-user',
                                widgets: ['personCard'],
                            },
                        ],
                    },
                },
 
                browser: {
                    icon: 'pi pi-check-square',
                    toolbar: [
                        {
                            label: 'Create',
                            icon: 'pi pi-plus',
                            action: 'component/party.consent.new',
                            permission: 'party.consent.add',
                        },
                        {
                            label: 'Edit',
                            icon: 'pi pi-pencil',
                            enabled: 'current' as const,
                            method: 'component/party.consent.open',
                            params: '${current}',
                        },
                        {
                            label: 'Report',
                            icon: 'pi pi-chart-bar',
                            action: 'component/party.consent.report',
                        },
                        {
                            label: 'Delete',
                            icon: 'pi pi-trash',
                            enabled: 'selected' as const,
                            confirm: 'Delete selected consent record?',
                            method: 'party.consent.remove',
                            params: {consentId: '${consentId}'},
                        },
                    ],
                },
            };
        },
);