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

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

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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 2311x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x  
import {model} from '@feasibleone/blong';
 
export default model(
    () =>
        async function partyOrganizationModel() {
            return {
                subject: 'party',
                object: 'organization',
                objectTitle: 'Organization',
                public: true,
                nameField: 'organization.legalName',
 
                schema: {
                    properties: {
                        organization: {
                            properties: {
                                legalName: {title: 'Legal Name'},
                                tradingName: {title: 'Trading Name'},
                                registrationNumber: {title: 'Registration Number'},
                                taxId: {title: 'Tax ID'},
                                establishedDate: {title: 'Date Established'},
                                industry: {title: 'Industry', filter: true},
                                website: {title: 'Website'},
                                notes: {title: 'Notes'},
                                // server schema defined
                                // organizationId: {},
                            },
                            widget: {
                                columns: [
                                    'legalName',
                                    'industry',
                                    'registrationNumber',
                                    'establishedDate',
                                ],
                            },
                        },
                        /** Contact details card. */
                        contact: {
                            properties: {
                                contactType: {
                                    title: 'Contact Type',
                                    widget: {
                                        options: [
                                            {value: 'email', label: 'Email'},
                                            {value: 'phone', label: 'Phone'},
                                            {value: 'mobile', label: 'Mobile'},
                                            {value: 'fax', label: 'Fax'},
                                        ],
                                    },
                                },
                                contactValue: {title: 'Contact Value'},
                                isPrimary: {title: 'Primary'},
                            },
                            widget: {
                                columns: ['contactType', 'contactValue', 'isPrimary'],
                            },
                        },
                        /** Address card. */
                        address: {
                            properties: {
                                addressType: {
                                    title: 'Address Type',
                                    widget: {
                                        options: [
                                            {value: 'home', label: 'Home'},
                                            {value: 'work', label: 'Work'},
                                            {value: 'billing', label: 'Billing'},
                                            {value: 'shipping', label: 'Shipping'},
                                        ],
                                    },
                                },
                                streetAddress: {title: 'Street Address'},
                                city: {title: 'City'},
                                stateProvince: {title: 'State / Province'},
                                postalCode: {title: 'Postal Code'},
                                isPrimary: {title: 'Primary'},
                            },
                            widget: {
                                columns: ['addressType', 'streetAddress', 'city', 'isPrimary'],
                            },
                        },
                        /** Identifier card. */
                        identifier: {
                            properties: {
                                identifierType: {
                                    title: 'Identifier Type',
                                    widget: {
                                        options: [
                                            {value: 'taxId', label: 'Tax ID'},
                                            {value: 'registrationNo', label: 'Registration No'},
                                            {value: 'duns', label: 'DUNS Number'},
                                            {value: 'lei', label: 'Legal Entity Identifier'},
                                        ],
                                    },
                                },
                                identifierValue: {title: 'Identifier Value'},
                                issuingAuthority: {title: 'Issuing Authority'},
                                issuedDate: {title: 'Issue Date'},
                                expiryDate: {title: 'Expiry Date'},
                            },
                            widget: {
                                columns: [
                                    'identifierType',
                                    'identifierValue',
                                    'issuingAuthority',
                                    'expiryDate',
                                ],
                            },
                        },
                        /**
                         * Units belonging to this organization.
                         *
                         * Hierarchy relationships (unit → organization) are stored in
                         * core.triple with predicate \"belongsTo\". This card will be
                         * populated by a custom adapter handler that traverses core.triple
                         * — placeholder for future implementation or realm contribution.
                         */
                    },
                },
 
                cards: {
                    browse: {
                        label: 'Organizations',
                        widgets: ['organization'],
                    },
                    details: {
                        label: 'Organization Details',
                        className: 'col-12',
                        widgets: [
                            'organization.legalName',
                            'organization.tradingName',
                            'organization.registrationNumber',
                            'organization.taxId',
                            'organization.establishedDate',
                            'organization.industry',
                            'organization.website',
                            'organization.notes',
                        ],
                    },
                    contactCard: {
                        label: 'Contact Details',
                        widgets: ['contact'],
                    },
                    addressCard: {
                        label: 'Addresses',
                        widgets: ['address'],
                    },
                    identifierCard: {
                        label: 'Identifiers',
                        widgets: ['identifier'],
                    },
                    /**
                     * Units tab — placeholder for core.triple-based hierarchy
                     * queries. Add a card and widget here once a custom adapter
                     * handler for unit→organization membership is implemented.
                     */
                },
 
                layouts: {
                    edit: [['details']],
                    editThumbIndex: {
                        orientation: 'left',
                        items: [
                            {
                                id: 'details',
                                label: 'Details',
                                icon: 'pi pi-building',
                                widgets: ['details'],
                            },
                            {
                                id: 'contact',
                                label: 'Contact',
                                icon: 'pi pi-envelope',
                                widgets: ['contactCard'],
                            },
                            {
                                id: 'address',
                                label: 'Addresses',
                                icon: 'pi pi-map-marker',
                                widgets: ['addressCard'],
                            },
                            {
                                id: 'identifiers',
                                label: 'Identifiers',
                                icon: 'pi pi-id-card',
                                widgets: ['identifierCard'],
                            },
                            /**
                             * Units tab — placeholder. Add widgets here once a
                             * custom adapter handler queries core.triple for unit →
                             * organization membership.
                             */
                        ],
                    },
                },
 
                browser: {
                    icon: 'pi pi-building',
                    toolbar: [
                        {
                            label: 'Create',
                            icon: 'pi pi-plus',
                            action: 'component/party.organization.new',
                            permission: 'party.organization.add',
                        },
                        {
                            label: 'Edit',
                            icon: 'pi pi-pencil',
                            enabled: 'current' as const,
                            method: 'component/party.organization.open',
                            params: '${current}',
                        },
                        {
                            label: 'Report',
                            icon: 'pi pi-chart-bar',
                            action: 'component/party.organization.report',
                        },
                        {
                            label: 'Delete',
                            icon: 'pi pi-trash',
                            enabled: 'selected' as const,
                            confirm: 'Delete selected organization record?',
                            method: 'party.organization.remove',
                            params: {organizationId: '${organizationId}'},
                        },
                    ],
                },
            };
        },
);