@sdcorejs/angular 19.3.2 → 19.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/THEME.md +58 -6
- package/assets/scss/core/form.scss +291 -3
- package/assets/scss/themes/_component-tokens.scss +35 -6
- package/components/badge/index.d.ts +1 -0
- package/components/badge/src/badge.model.d.ts +19 -0
- package/components/section/index.d.ts +1 -0
- package/components/section/src/section-registry.d.ts +11 -0
- package/components/splitter/index.d.ts +1 -1
- package/components/tab-router/src/actions/tab-router.action.d.ts +1 -1
- package/components/tab-router/src/components/tab-router-item/tab-router-item.component.d.ts +4 -2
- package/components/tab-router/src/components/tab-router-nav/tab-router-nav.component.d.ts +31 -3
- package/components/tab-router/src/components/tab-router-outlet/tab-router-outlet.component.d.ts +6 -1
- package/components/tab-router/src/models/tab-router.model.d.ts +5 -0
- package/components/tab-router/src/pipes/tab-info.pipe.d.ts +7 -0
- package/components/tab-router/src/services/tab-router.service.d.ts +5 -0
- package/components/table/index.d.ts +2 -0
- package/components/table/src/components/filter/external-filter/external-filter.component.d.ts +5 -1
- package/components/table/src/components/mobile-cards/mobile-cards.component.d.ts +4 -0
- package/components/table/src/configurations/index.d.ts +1 -0
- package/components/table/src/configurations/table-layout.d.ts +16 -0
- package/components/table/src/configurations/table.configuration.d.ts +3 -1
- package/components/table/src/models/index.d.ts +1 -0
- package/components/table/src/models/table-column.model.d.ts +3 -10
- package/components/table/src/models/table-item.model.d.ts +4 -1
- package/components/table/src/models/table-option-loading.model.d.ts +42 -0
- package/components/table/src/models/table-option.model.d.ts +6 -0
- package/components/table/src/services/table-filter/table-filter.model.d.ts +5 -0
- package/components/table/src/services/table-loading/table-loading.util.d.ts +91 -0
- package/components/table/src/services/tree/tree.util.d.ts +2 -0
- package/components/table/src/table.component.d.ts +23 -0
- package/components/upload-file/src/components/file-type-icon/file-type-icon.component.d.ts +15 -0
- package/components/upload-file/src/components/preview/preview.component.d.ts +88 -10
- package/components/upload-file/src/configurations/upload-file.configuration.d.ts +1 -1
- package/components/upload-file/src/helpers/file-type.d.ts +25 -0
- package/components/upload-file/src/pipes/file-meta.pipe.d.ts +9 -0
- package/components/upload-file/src/pipes/file-reason.pipe.d.ts +11 -0
- package/components/upload-file/src/pipes/index.d.ts +2 -0
- package/components/upload-file/src/upload-file.component.d.ts +89 -8
- package/fesm2022/sdcorejs-angular-components-badge.mjs +2 -2
- package/fesm2022/sdcorejs-angular-components-badge.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-form-generic.mjs +3 -3
- package/fesm2022/sdcorejs-angular-components-form-generic.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-section.mjs +15 -3
- package/fesm2022/sdcorejs-angular-components-section.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-side-drawer.mjs +2 -2
- package/fesm2022/sdcorejs-angular-components-side-drawer.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-splitter.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-tab-router.mjs +390 -75
- package/fesm2022/sdcorejs-angular-components-tab-router.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-table.mjs +443 -15
- package/fesm2022/sdcorejs-angular-components-table.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-upload-file.mjs +886 -173
- package/fesm2022/sdcorejs-angular-components-upload-file.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-autocomplete.mjs +7 -2
- package/fesm2022/sdcorejs-angular-forms-autocomplete.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-chip-calendar.mjs +5 -2
- package/fesm2022/sdcorejs-angular-forms-chip-calendar.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-chip.mjs +421 -121
- package/fesm2022/sdcorejs-angular-forms-chip.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-date-range.mjs +4 -0
- package/fesm2022/sdcorejs-angular-forms-date-range.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-date.mjs +4 -0
- package/fesm2022/sdcorejs-angular-forms-date.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-datetime.mjs +4 -0
- package/fesm2022/sdcorejs-angular-forms-datetime.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-input-number.mjs +17 -2
- package/fesm2022/sdcorejs-angular-forms-input-number.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-input.mjs +4 -0
- package/fesm2022/sdcorejs-angular-forms-input.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-select.mjs +26 -20
- package/fesm2022/sdcorejs-angular-forms-select.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-textarea.mjs +14 -1
- package/fesm2022/sdcorejs-angular-forms-textarea.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-i18n.mjs +210 -0
- package/fesm2022/sdcorejs-angular-i18n.mjs.map +1 -1
- package/fesm2022/{sdcorejs-angular-modules-generic-generic-configuration.page-BFxO3eHX.mjs → sdcorejs-angular-modules-generic-generic-configuration.page-Bk3PrEf3.mjs} +3 -3
- package/fesm2022/{sdcorejs-angular-modules-generic-generic-configuration.page-BFxO3eHX.mjs.map → sdcorejs-angular-modules-generic-generic-configuration.page-Bk3PrEf3.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-generic-generic-form-host.page-Csy2fShj.mjs → sdcorejs-angular-modules-generic-generic-form-host.page-CwUegGgG.mjs} +3 -3
- package/fesm2022/{sdcorejs-angular-modules-generic-generic-form-host.page-Csy2fShj.mjs.map → sdcorejs-angular-modules-generic-generic-form-host.page-CwUegGgG.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-generic-generic-list.page-BIIxNR6k.mjs → sdcorejs-angular-modules-generic-generic-list.page-lF2trhfp.mjs} +3 -3
- package/fesm2022/{sdcorejs-angular-modules-generic-generic-list.page-BIIxNR6k.mjs.map → sdcorejs-angular-modules-generic-generic-list.page-lF2trhfp.mjs.map} +1 -1
- package/fesm2022/{sdcorejs-angular-modules-generic-sdcorejs-angular-modules-generic-DjDsau9C.mjs → sdcorejs-angular-modules-generic-sdcorejs-angular-modules-generic-BbmeOduc.mjs} +4 -4
- package/fesm2022/{sdcorejs-angular-modules-generic-sdcorejs-angular-modules-generic-DjDsau9C.mjs.map → sdcorejs-angular-modules-generic-sdcorejs-angular-modules-generic-BbmeOduc.mjs.map} +1 -1
- package/fesm2022/sdcorejs-angular-modules-generic.mjs +1 -1
- package/fesm2022/sdcorejs-angular-modules-layout.mjs +265 -10
- package/fesm2022/sdcorejs-angular-modules-layout.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-modules-pattern-api-error-BBWwQ6h2.mjs +23 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-api-error-BBWwQ6h2.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-approval-inbox-BMwD6_FC.mjs +16 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-approval-inbox-BMwD6_FC.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-base-api.service-CVEKaR8U.mjs +51 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-base-api.service-CVEKaR8U.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-create-side-drawer.component-BqHybMk0.mjs +130 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-create-side-drawer.component-BqHybMk0.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-create-side-drawer.component-CND3d2zl.mjs +131 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-create-side-drawer.component-CND3d2zl.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-create.component-BbDoQccI.mjs +99 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-create.component-BbDoQccI.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-create.component-CB_wJIP8.mjs +460 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-create.component-CB_wJIP8.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-create.component-DlP4BrhU.mjs +118 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-create.component-DlP4BrhU.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-customer.model-C3fr4yNw.mjs +18 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-customer.model-C3fr4yNw.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-customer.service-VAMePx_q.mjs +66 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-customer.service-VAMePx_q.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-detail-side-drawer.component-BD79VR0c.mjs +148 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-detail-side-drawer.component-BD79VR0c.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-detail.component-B1rFhbOc.mjs +172 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-detail.component-B1rFhbOc.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-detail.component-BhCjw6ZL.mjs +467 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-detail.component-BhCjw6ZL.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-detail.component-CnL2FzCx.mjs +90 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-detail.component-CnL2FzCx.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-flow.component-BeH-NYvE.mjs +514 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-flow.component-BeH-NYvE.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-form-api-errors-DpnYSG2j.mjs +61 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-form-api-errors-DpnYSG2j.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-form.component-1bi0JZdf.mjs +170 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-form.component-1bi0JZdf.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-form.component-D6eKR2cq.mjs +87 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-form.component-D6eKR2cq.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-form.component-FcJS3Nbd.mjs +232 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-form.component-FcJS3Nbd.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-view.component-BA-3FR1J.mjs +70 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-general-information-view.component-BA-3FR1J.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-index.component-BAZLCVci.mjs +100 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-index.component-BAZLCVci.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-lines-form.component-ikk0cK1M.mjs +522 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-lines-form.component-ikk0cK1M.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-Cex41xzy.mjs +164 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-Cex41xzy.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-D643jEmo.mjs +629 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-D643jEmo.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-DTWHhNNl.mjs +71 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-DTWHhNNl.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-YJUJsrIZ.mjs +115 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-YJUJsrIZ.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-qH-YO6wP.mjs +118 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-list.component-qH-YO6wP.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-mock-backend.factory-S0Vuy6Oc.mjs +1069 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-mock-backend.factory-S0Vuy6Oc.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-pattern-source-viewer-BpLQaYP5.mjs +186 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-pattern-source-viewer-BpLQaYP5.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-pattern-source.generated-BrejHvB2.mjs +97 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-pattern-source.generated-BrejHvB2.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-product.model-BoHLJ8vf.mjs +12 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-product.model-BoHLJ8vf.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-product.service-Ba73HPGG.mjs +48 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-product.service-Ba73HPGG.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-profile.component-CBlN7eEn.mjs +295 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-profile.component-CBlN7eEn.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-BvzFafUW.mjs +74 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-BvzFafUW.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-C3uWi8JZ.mjs +165 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-C3uWi8JZ.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-C5ELCTEw.mjs +74 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-C5ELCTEw.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-ClQwnO4h.mjs +50 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-ClQwnO4h.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-DTUxYZ6g.mjs +66 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-DTUxYZ6g.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-DpCuYBlL.mjs +99 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-DpCuYBlL.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-DwZWxmJf.mjs +45 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-DwZWxmJf.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-ydOZduls.mjs +43 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-routes-ydOZduls.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-sdcorejs-angular-modules-pattern-D3B5I9hg.mjs +406 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-sdcorejs-angular-modules-pattern-D3B5I9hg.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-shell.component-BW-i6BHg.mjs +317 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-shell.component-BW-i6BHg.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-update-side-drawer.component-By1mYFa_.mjs +132 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-update-side-drawer.component-By1mYFa_.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-update-side-drawer.component-DwcyKb4j.mjs +143 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-update-side-drawer.component-DwcyKb4j.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-update.component-BBR8360C.mjs +100 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-update.component-BBR8360C.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-update.component-CAtqPgIH.mjs +357 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-update.component-CAtqPgIH.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-update.component-DjMChf6s.mjs +128 -0
- package/fesm2022/sdcorejs-angular-modules-pattern-update.component-DjMChf6s.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-pattern.mjs +2 -0
- package/fesm2022/sdcorejs-angular-modules-pattern.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-services-unsaved-changes.mjs +104 -4
- package/fesm2022/sdcorejs-angular-services-unsaved-changes.mjs.map +1 -1
- package/forms/chip/src/chip.component.d.ts +135 -19
- package/forms/chip/src/index.d.ts +0 -1
- package/i18n/src/en.d.ts +42 -0
- package/modules/layout/components/index.d.ts +2 -0
- package/modules/layout/components/page/page-form-leave.guard.d.ts +9 -0
- package/modules/layout/components/page/page.component.d.ts +38 -2
- package/modules/layout/components/page-list/page-list.component.d.ts +42 -0
- package/modules/layout/components/shared/context-switcher/context-switcher.component.d.ts +1 -1
- package/modules/pattern/README.md +76 -0
- package/modules/pattern/configurations/pattern.configuration.d.ts +30 -0
- package/modules/pattern/configurations/provide-sd-patterns.d.ts +19 -0
- package/modules/pattern/core/mock-api/mock-api.interceptor.d.ts +8 -0
- package/modules/pattern/core/mock-api/mock-api.model.d.ts +62 -0
- package/modules/pattern/core/mock-api/mock-api.state.d.ts +36 -0
- package/modules/pattern/core/mock-api/mock-backend.d.ts +18 -0
- package/modules/pattern/core/mock-api/mock-backend.factory.d.ts +3 -0
- package/modules/pattern/core/mock-api/prng.d.ts +4 -0
- package/modules/pattern/core/mock-api/resources/approval.resource.d.ts +14 -0
- package/modules/pattern/core/mock-api/resources/category.resource.d.ts +9 -0
- package/modules/pattern/core/mock-api/resources/customer.resource.d.ts +22 -0
- package/modules/pattern/core/mock-api/resources/index.d.ts +3 -0
- package/modules/pattern/core/mock-api/resources/names.d.ts +5 -0
- package/modules/pattern/core/mock-api/resources/order.resource.d.ts +44 -0
- package/modules/pattern/core/mock-api/resources/partner.resource.d.ts +16 -0
- package/modules/pattern/core/mock-api/resources/product.resource.d.ts +13 -0
- package/modules/pattern/core/mock-api/resources/settings.resource.d.ts +18 -0
- package/modules/pattern/core/pattern-shell/catalog/pattern-catalog.d.ts +22 -0
- package/modules/pattern/core/pattern-shell/index/index.component.d.ts +9 -0
- package/modules/pattern/core/pattern-shell/settings/pattern-settings.store.d.ts +57 -0
- package/modules/pattern/core/pattern-shell/settings/settings-button.component.d.ts +44 -0
- package/modules/pattern/core/pattern-shell/shell/pattern-source-viewer.d.ts +8 -0
- package/modules/pattern/core/pattern-shell/shell/shell.component.d.ts +13 -0
- package/modules/pattern/core/pattern-shell/source/pattern-source.generated.d.ts +1 -0
- package/modules/pattern/core/pattern-shell/source/source-drawer.component.d.ts +27 -0
- package/modules/pattern/core/pattern-shell/toolbar/toolbar.component.d.ts +24 -0
- package/modules/pattern/core/permission/pattern-permission.d.ts +15 -0
- package/modules/pattern/core/permission/pattern-role.store.d.ts +13 -0
- package/modules/pattern/core/session-state.d.ts +4 -0
- package/modules/pattern/docs/detail.md +237 -0
- package/modules/pattern/docs/drawer.md +484 -0
- package/modules/pattern/docs/flow.md +631 -0
- package/modules/pattern/docs/form.md +518 -0
- package/modules/pattern/docs/header-actions.md +342 -0
- package/modules/pattern/docs/list.md +247 -0
- package/modules/pattern/docs/relation.md +180 -0
- package/modules/pattern/docs/select.md +206 -0
- package/modules/pattern/docs/split.md +350 -0
- package/modules/pattern/docs/states.md +168 -0
- package/modules/pattern/features/approval/entity.resolver.d.ts +4 -0
- package/modules/pattern/features/approval/entity.resolver.ts +21 -0
- package/modules/pattern/features/approval/pages/detail/detail.component.d.ts +13 -0
- package/modules/pattern/features/approval/pages/detail/detail.component.ts +139 -0
- package/modules/pattern/features/approval/pages/list/approval-inbox.d.ts +7 -0
- package/modules/pattern/features/approval/pages/list/approval-inbox.ts +7 -0
- package/modules/pattern/features/approval/pages/list/list.component.d.ts +26 -0
- package/modules/pattern/features/approval/pages/list/list.component.html +20 -0
- package/modules/pattern/features/approval/pages/list/list.component.ts +149 -0
- package/modules/pattern/features/approval/routes.d.ts +3 -0
- package/modules/pattern/features/approval/routes.ts +30 -0
- package/modules/pattern/features/approval/services/approval.model.d.ts +37 -0
- package/modules/pattern/features/approval/services/approval.model.ts +38 -0
- package/modules/pattern/features/approval/services/approval.service.d.ts +12 -0
- package/modules/pattern/features/approval/services/approval.service.ts +23 -0
- package/modules/pattern/features/category/components/create-side-drawer/create-side-drawer.component.d.ts +23 -0
- package/modules/pattern/features/category/components/create-side-drawer/create-side-drawer.component.ts +123 -0
- package/modules/pattern/features/category/components/general-information-form/general-information-form.component.d.ts +20 -0
- package/modules/pattern/features/category/components/general-information-form/general-information-form.component.ts +61 -0
- package/modules/pattern/features/category/components/update-side-drawer/update-side-drawer.component.d.ts +23 -0
- package/modules/pattern/features/category/components/update-side-drawer/update-side-drawer.component.ts +134 -0
- package/modules/pattern/features/category/entity.resolver.d.ts +6 -0
- package/modules/pattern/features/category/entity.resolver.ts +27 -0
- package/modules/pattern/features/category/pages/list/list.component.d.ts +17 -0
- package/modules/pattern/features/category/pages/list/list.component.html +20 -0
- package/modules/pattern/features/category/pages/list/list.component.ts +105 -0
- package/modules/pattern/features/category/routes.d.ts +3 -0
- package/modules/pattern/features/category/routes.ts +42 -0
- package/modules/pattern/features/category/services/category.model.d.ts +34 -0
- package/modules/pattern/features/category/services/category.model.ts +39 -0
- package/modules/pattern/features/category/services/category.service.d.ts +17 -0
- package/modules/pattern/features/category/services/category.service.ts +36 -0
- package/modules/pattern/features/customer/components/create-side-drawer/create-side-drawer.component.d.ts +24 -0
- package/modules/pattern/features/customer/components/create-side-drawer/create-side-drawer.component.ts +131 -0
- package/modules/pattern/features/customer/components/customer-select/customer-select.component.d.ts +20 -0
- package/modules/pattern/features/customer/components/customer-select/customer-select.component.ts +72 -0
- package/modules/pattern/features/customer/components/customer-type-select/customer-type-select.component.d.ts +20 -0
- package/modules/pattern/features/customer/components/customer-type-select/customer-type-select.component.ts +30 -0
- package/modules/pattern/features/customer/components/debts-view/debts-view.component.d.ts +11 -0
- package/modules/pattern/features/customer/components/debts-view/debts-view.component.ts +28 -0
- package/modules/pattern/features/customer/components/detail-side-drawer/detail-side-drawer.component.d.ts +20 -0
- package/modules/pattern/features/customer/components/detail-side-drawer/detail-side-drawer.component.ts +106 -0
- package/modules/pattern/features/customer/components/documents-view/documents-view.component.d.ts +14 -0
- package/modules/pattern/features/customer/components/documents-view/documents-view.component.ts +50 -0
- package/modules/pattern/features/customer/components/general-information-form/general-information-form.component.d.ts +33 -0
- package/modules/pattern/features/customer/components/general-information-form/general-information-form.component.ts +140 -0
- package/modules/pattern/features/customer/components/general-information-view/general-information-view.component.d.ts +9 -0
- package/modules/pattern/features/customer/components/general-information-view/general-information-view.component.ts +39 -0
- package/modules/pattern/features/customer/components/orders-view/orders-view.component.d.ts +11 -0
- package/modules/pattern/features/customer/components/orders-view/orders-view.component.ts +35 -0
- package/modules/pattern/features/customer/components/summary-cards/summary-cards.component.d.ts +22 -0
- package/modules/pattern/features/customer/components/summary-cards/summary-cards.component.ts +101 -0
- package/modules/pattern/features/customer/components/update-side-drawer/update-side-drawer.component.d.ts +24 -0
- package/modules/pattern/features/customer/components/update-side-drawer/update-side-drawer.component.ts +127 -0
- package/modules/pattern/features/customer/entity.resolver.d.ts +4 -0
- package/modules/pattern/features/customer/entity.resolver.ts +21 -0
- package/modules/pattern/features/customer/pages/list/list.component.d.ts +19 -0
- package/modules/pattern/features/customer/pages/list/list.component.html +22 -0
- package/modules/pattern/features/customer/pages/list/list.component.ts +113 -0
- package/modules/pattern/features/customer/pages/profile/profile.component.d.ts +31 -0
- package/modules/pattern/features/customer/pages/profile/profile.component.ts +120 -0
- package/modules/pattern/features/customer/pipes/customer-detail.pipe.d.ts +14 -0
- package/modules/pattern/features/customer/pipes/customer-detail.pipe.ts +18 -0
- package/modules/pattern/features/customer/routes.d.ts +6 -0
- package/modules/pattern/features/customer/routes.ts +59 -0
- package/modules/pattern/features/customer/services/customer.model.d.ts +77 -0
- package/modules/pattern/features/customer/services/customer.model.ts +87 -0
- package/modules/pattern/features/customer/services/customer.service.d.ts +24 -0
- package/modules/pattern/features/customer/services/customer.service.ts +79 -0
- package/modules/pattern/features/import/components/mapping-form/mapping-form.component.d.ts +21 -0
- package/modules/pattern/features/import/components/mapping-form/mapping-form.component.ts +41 -0
- package/modules/pattern/features/import/components/preview-view/preview-view.component.d.ts +10 -0
- package/modules/pattern/features/import/components/preview-view/preview-view.component.ts +44 -0
- package/modules/pattern/features/import/pages/flow/flow.component.d.ts +43 -0
- package/modules/pattern/features/import/pages/flow/flow.component.ts +269 -0
- package/modules/pattern/features/import/routes.d.ts +2 -0
- package/modules/pattern/features/import/routes.ts +19 -0
- package/modules/pattern/features/import/services/import.model.d.ts +38 -0
- package/modules/pattern/features/import/services/import.model.ts +82 -0
- package/modules/pattern/features/import/services/import.service.d.ts +15 -0
- package/modules/pattern/features/import/services/import.service.ts +18 -0
- package/modules/pattern/features/order/components/approval-steps/approval-steps.component.d.ts +9 -0
- package/modules/pattern/features/order/components/approval-steps/approval-steps.component.ts +74 -0
- package/modules/pattern/features/order/components/bulk-result/bulk-result.component.d.ts +22 -0
- package/modules/pattern/features/order/components/bulk-result/bulk-result.component.ts +46 -0
- package/modules/pattern/features/order/components/general-information-form/general-information-form.component.d.ts +30 -0
- package/modules/pattern/features/order/components/general-information-form/general-information-form.component.ts +96 -0
- package/modules/pattern/features/order/components/lines-form/lines-form.component.d.ts +33 -0
- package/modules/pattern/features/order/components/lines-form/lines-form.component.ts +205 -0
- package/modules/pattern/features/order/components/lines-view/lines-view.component.d.ts +12 -0
- package/modules/pattern/features/order/components/lines-view/lines-view.component.ts +42 -0
- package/modules/pattern/features/order/components/summary-cards/summary-cards.component.d.ts +25 -0
- package/modules/pattern/features/order/components/summary-cards/summary-cards.component.ts +128 -0
- package/modules/pattern/features/order/entity.resolver.d.ts +9 -0
- package/modules/pattern/features/order/entity.resolver.ts +37 -0
- package/modules/pattern/features/order/pages/create/create.component.d.ts +16 -0
- package/modules/pattern/features/order/pages/create/create.component.ts +99 -0
- package/modules/pattern/features/order/pages/detail/detail.component.d.ts +26 -0
- package/modules/pattern/features/order/pages/detail/detail.component.ts +222 -0
- package/modules/pattern/features/order/pages/list/list.component.d.ts +29 -0
- package/modules/pattern/features/order/pages/list/list.component.html +38 -0
- package/modules/pattern/features/order/pages/list/list.component.ts +291 -0
- package/modules/pattern/features/order/pages/update/update.component.d.ts +20 -0
- package/modules/pattern/features/order/pages/update/update.component.ts +119 -0
- package/modules/pattern/features/order/routes.d.ts +7 -0
- package/modules/pattern/features/order/routes.ts +54 -0
- package/modules/pattern/features/order/services/order.model.d.ts +106 -0
- package/modules/pattern/features/order/services/order.model.ts +109 -0
- package/modules/pattern/features/order/services/order.service.d.ts +25 -0
- package/modules/pattern/features/order/services/order.service.ts +63 -0
- package/modules/pattern/features/partner/pages/create/create.component.d.ts +41 -0
- package/modules/pattern/features/partner/pages/create/create.component.ts +324 -0
- package/modules/pattern/features/partner/routes.d.ts +2 -0
- package/modules/pattern/features/partner/routes.ts +20 -0
- package/modules/pattern/features/partner/services/partner.model.d.ts +30 -0
- package/modules/pattern/features/partner/services/partner.model.ts +30 -0
- package/modules/pattern/features/partner/services/partner.service.d.ts +13 -0
- package/modules/pattern/features/partner/services/partner.service.ts +17 -0
- package/modules/pattern/features/product/components/general-information-form/general-information-form.component.d.ts +23 -0
- package/modules/pattern/features/product/components/general-information-form/general-information-form.component.ts +88 -0
- package/modules/pattern/features/product/components/product-select/product-select.component.d.ts +20 -0
- package/modules/pattern/features/product/components/product-select/product-select.component.ts +65 -0
- package/modules/pattern/features/product/components/product-status-select/product-status-select.component.d.ts +22 -0
- package/modules/pattern/features/product/components/product-status-select/product-status-select.component.ts +30 -0
- package/modules/pattern/features/product/entity.resolver.d.ts +4 -0
- package/modules/pattern/features/product/entity.resolver.ts +21 -0
- package/modules/pattern/features/product/pages/create/create.component.d.ts +15 -0
- package/modules/pattern/features/product/pages/create/create.component.ts +85 -0
- package/modules/pattern/features/product/pages/detail/detail.component.d.ts +10 -0
- package/modules/pattern/features/product/pages/detail/detail.component.ts +53 -0
- package/modules/pattern/features/product/pages/list/list.component.d.ts +15 -0
- package/modules/pattern/features/product/pages/list/list.component.html +30 -0
- package/modules/pattern/features/product/pages/list/list.component.ts +71 -0
- package/modules/pattern/features/product/pages/update/update.component.d.ts +16 -0
- package/modules/pattern/features/product/pages/update/update.component.ts +86 -0
- package/modules/pattern/features/product/pipes/product-detail.pipe.d.ts +14 -0
- package/modules/pattern/features/product/pipes/product-detail.pipe.ts +18 -0
- package/modules/pattern/features/product/routes.d.ts +3 -0
- package/modules/pattern/features/product/routes.ts +48 -0
- package/modules/pattern/features/product/services/product.model.d.ts +34 -0
- package/modules/pattern/features/product/services/product.model.ts +38 -0
- package/modules/pattern/features/product/services/product.service.d.ts +17 -0
- package/modules/pattern/features/product/services/product.service.ts +48 -0
- package/modules/pattern/features/settings/pages/update/update.component.d.ts +26 -0
- package/modules/pattern/features/settings/pages/update/update.component.ts +227 -0
- package/modules/pattern/features/settings/routes.d.ts +3 -0
- package/modules/pattern/features/settings/routes.ts +24 -0
- package/modules/pattern/features/settings/services/settings.model.d.ts +17 -0
- package/modules/pattern/features/settings/services/settings.model.ts +18 -0
- package/modules/pattern/features/settings/services/settings.service.d.ts +10 -0
- package/modules/pattern/features/settings/services/settings.service.ts +15 -0
- package/modules/pattern/features/settings/settings.resolver.d.ts +4 -0
- package/modules/pattern/features/settings/settings.resolver.ts +8 -0
- package/modules/pattern/index.d.ts +3 -0
- package/modules/pattern/routes.d.ts +6 -0
- package/modules/pattern/services/base-api.service.d.ts +16 -0
- package/modules/pattern/utils/api-error.d.ts +4 -0
- package/modules/pattern/utils/focus-first-invalid.d.ts +5 -0
- package/modules/pattern/utils/form-api-errors.d.ts +16 -0
- package/modules/pattern/utils/resource-url.d.ts +2 -0
- package/package.json +13 -9
- package/services/unsaved-changes/src/unsaved-changes.adapters.d.ts +9 -0
- package/services/unsaved-changes/src/unsaved-changes.model.d.ts +2 -0
- package/forms/chip/src/pipes/index.d.ts +0 -1
- package/forms/chip/src/pipes/removable-chip.pipe.d.ts +0 -8
|
@@ -0,0 +1,1069 @@
|
|
|
1
|
+
import { FilterUtilities } from '@sdcorejs/utils/fns';
|
|
2
|
+
import { c as PatternMockError, r as readSessionValue, w as writeSessionValue } from './sdcorejs-angular-modules-pattern-sdcorejs-angular-modules-pattern-D3B5I9hg.mjs';
|
|
3
|
+
|
|
4
|
+
const STORAGE_PREFIX = 'sd-pattern.db.';
|
|
5
|
+
const notFound = () => new PatternMockError(404, { message: 'Không tìm thấy bản ghi.' });
|
|
6
|
+
const asBody = (body) => body && typeof body === 'object' && !Array.isArray(body) ? body : {};
|
|
7
|
+
const parseJson = (raw, fallback) => {
|
|
8
|
+
if (!raw)
|
|
9
|
+
return fallback;
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(raw);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
throw new PatternMockError(400, { message: 'Tham số truy vấn không hợp lệ.' });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const valueAt = (record, path) => path
|
|
18
|
+
.split('.')
|
|
19
|
+
.reduce((value, key) => (value && typeof value === 'object' ? value[key] : undefined), record);
|
|
20
|
+
const compare = (left, right) => {
|
|
21
|
+
if (left === right)
|
|
22
|
+
return 0;
|
|
23
|
+
if (left === null || left === undefined || left === '')
|
|
24
|
+
return 1;
|
|
25
|
+
if (right === null || right === undefined || right === '')
|
|
26
|
+
return -1;
|
|
27
|
+
if (typeof left === 'number' && typeof right === 'number')
|
|
28
|
+
return left - right;
|
|
29
|
+
return String(left).localeCompare(String(right), 'vi', { numeric: true });
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* In-memory API behind the pattern screens: one collection per resource, seeded on first use and kept in
|
|
33
|
+
* sessionStorage when `storage` is `'session'`. Answers like the blueprint transport:
|
|
34
|
+
* `GET <name>` (`pageNumber`, `pageSize` and JSON `filters` / `orders`), `GET|PUT|DELETE <name>/:id`, `POST <name>`,
|
|
35
|
+
* `POST <name>/:id/<action>` and `POST <name>/bulk/<action>` with `{ ids }` or `{ items }`.
|
|
36
|
+
*/
|
|
37
|
+
class PatternMockBackend {
|
|
38
|
+
storage;
|
|
39
|
+
#resources = new Map();
|
|
40
|
+
#collections = new Map();
|
|
41
|
+
#context;
|
|
42
|
+
constructor(resources, storage) {
|
|
43
|
+
this.storage = storage;
|
|
44
|
+
resources.forEach(resource => this.#resources.set(resource.name, resource));
|
|
45
|
+
this.#context = {
|
|
46
|
+
collection: (name) => this.collection(name),
|
|
47
|
+
save: (name, records) => this.#save(name, [...records]),
|
|
48
|
+
nextId: name => String(this.collection(name).reduce((max, record) => Math.max(max, Number(record.id) || 0), 0) + 1),
|
|
49
|
+
now: () => new Date(),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Records of a resource: stored copy first, then the seed. */
|
|
53
|
+
collection(name) {
|
|
54
|
+
const cached = this.#collections.get(name);
|
|
55
|
+
if (cached)
|
|
56
|
+
return cached;
|
|
57
|
+
const resource = this.#resources.get(name);
|
|
58
|
+
if (!resource)
|
|
59
|
+
throw notFound();
|
|
60
|
+
const stored = this.storage === 'session' ? readSessionValue(STORAGE_PREFIX + name, null) : null;
|
|
61
|
+
const records = Array.isArray(stored) ? stored : resource.seed();
|
|
62
|
+
this.#collections.set(name, records);
|
|
63
|
+
return records;
|
|
64
|
+
}
|
|
65
|
+
/** Drops every change and goes back to the seeds. */
|
|
66
|
+
reset() {
|
|
67
|
+
this.#resources.forEach((_, name) => writeSessionValue(STORAGE_PREFIX + name, undefined));
|
|
68
|
+
this.#collections.clear();
|
|
69
|
+
}
|
|
70
|
+
/** Handles one request; throws `PatternMockError` for HTTP errors. */
|
|
71
|
+
handle(method, segments, query, rawBody, limit) {
|
|
72
|
+
const [name, ...rest] = segments;
|
|
73
|
+
const resource = name ? this.#resources.get(name) : undefined;
|
|
74
|
+
if (!resource)
|
|
75
|
+
throw notFound();
|
|
76
|
+
const body = asBody(rawBody);
|
|
77
|
+
const custom = resource.route?.(method, rest, query, body, this.#context);
|
|
78
|
+
if (custom)
|
|
79
|
+
return custom;
|
|
80
|
+
if (rest.length === 0 && method === 'GET')
|
|
81
|
+
return { body: this.#search(resource, query, limit) };
|
|
82
|
+
if (rest.length === 0 && method === 'POST')
|
|
83
|
+
return this.#create(resource, body);
|
|
84
|
+
if (rest[0] === 'bulk' && rest.length === 2 && method === 'POST')
|
|
85
|
+
return { body: this.#bulk(resource, rest[1], body) };
|
|
86
|
+
if (rest.length === 1) {
|
|
87
|
+
const id = rest[0];
|
|
88
|
+
if (method === 'GET')
|
|
89
|
+
return { body: this.#find(resource.name, id) };
|
|
90
|
+
if (method === 'PUT')
|
|
91
|
+
return { body: this.#update(resource, id, body) };
|
|
92
|
+
if (method === 'DELETE') {
|
|
93
|
+
this.#delete(resource, id);
|
|
94
|
+
return { status: 204, body: null };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (rest.length === 2 && method === 'POST')
|
|
98
|
+
return { body: this.#act(resource, rest[0], rest[1], body) };
|
|
99
|
+
throw new PatternMockError(405, { message: `Không hỗ trợ ${method} /${segments.join('/')}.` });
|
|
100
|
+
}
|
|
101
|
+
#save(name, records) {
|
|
102
|
+
this.#collections.set(name, records);
|
|
103
|
+
if (this.storage === 'session')
|
|
104
|
+
writeSessionValue(STORAGE_PREFIX + name, records);
|
|
105
|
+
}
|
|
106
|
+
#find(name, id) {
|
|
107
|
+
const record = this.collection(name).find(item => item.id === id);
|
|
108
|
+
if (!record)
|
|
109
|
+
throw notFound();
|
|
110
|
+
return record;
|
|
111
|
+
}
|
|
112
|
+
#search(resource, query, limit) {
|
|
113
|
+
const filters = parseJson(query.get('filters'), []);
|
|
114
|
+
const orders = parseJson(query.get('orders'), []);
|
|
115
|
+
const pageNumber = Math.max(0, Number(query.get('pageNumber') ?? 0) || 0);
|
|
116
|
+
const pageSize = Math.max(1, Number(query.get('pageSize') ?? 20) || 20);
|
|
117
|
+
const source = limit === undefined ? this.collection(resource.name) : this.collection(resource.name).slice(0, limit);
|
|
118
|
+
const matched = source.filter(record => FilterUtilities.match(filters, record, { fieldTypes: resource.fieldTypes }));
|
|
119
|
+
const sorted = orders.length
|
|
120
|
+
? [...matched].sort((left, right) => {
|
|
121
|
+
for (const order of orders) {
|
|
122
|
+
const result = compare(valueAt(left, String(order.field)), valueAt(right, String(order.field)));
|
|
123
|
+
if (result)
|
|
124
|
+
return order.direction === 'DESC' ? -result : result;
|
|
125
|
+
}
|
|
126
|
+
return 0;
|
|
127
|
+
})
|
|
128
|
+
: matched;
|
|
129
|
+
return { items: sorted.slice(pageNumber * pageSize, (pageNumber + 1) * pageSize), total: matched.length };
|
|
130
|
+
}
|
|
131
|
+
#create(resource, body) {
|
|
132
|
+
if (!resource.create)
|
|
133
|
+
throw new PatternMockError(405, { message: 'Không hỗ trợ tạo mới.' });
|
|
134
|
+
const records = this.collection(resource.name);
|
|
135
|
+
const record = resource.create(body, records, this.#context);
|
|
136
|
+
this.#save(resource.name, [record, ...records]);
|
|
137
|
+
return { status: 201, body: record };
|
|
138
|
+
}
|
|
139
|
+
#update(resource, id, body) {
|
|
140
|
+
if (!resource.update)
|
|
141
|
+
throw new PatternMockError(405, { message: 'Không hỗ trợ cập nhật.' });
|
|
142
|
+
const records = this.collection(resource.name);
|
|
143
|
+
const current = this.#find(resource.name, id);
|
|
144
|
+
const updated = resource.update(current, body, records, this.#context);
|
|
145
|
+
this.#save(resource.name, records.map(record => (record.id === id ? updated : record)));
|
|
146
|
+
return updated;
|
|
147
|
+
}
|
|
148
|
+
#delete(resource, id) {
|
|
149
|
+
const current = this.#find(resource.name, id);
|
|
150
|
+
resource.beforeDelete?.(current, this.#context);
|
|
151
|
+
this.#save(resource.name, this.collection(resource.name).filter(record => record.id !== id));
|
|
152
|
+
}
|
|
153
|
+
#act(resource, id, action, body) {
|
|
154
|
+
const handler = resource.actions?.[action];
|
|
155
|
+
if (!handler)
|
|
156
|
+
throw new PatternMockError(405, { message: `Không hỗ trợ tác vụ ${action}.` });
|
|
157
|
+
const updated = handler(this.#find(resource.name, id), body, this.#context);
|
|
158
|
+
this.#save(resource.name, this.collection(resource.name).map(record => (record.id === id ? updated : record)));
|
|
159
|
+
return updated;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Applies an action to every id and answers each one: a record in the wrong state fails alone, the others
|
|
163
|
+
* still change. Body: `{ ids: string[] }`, or `{ items: { id, ...data }[] }` when each record carries its own data.
|
|
164
|
+
*/
|
|
165
|
+
#bulk(resource, action, body) {
|
|
166
|
+
const items = Array.isArray(body['items'])
|
|
167
|
+
? body['items']
|
|
168
|
+
: Array.isArray(body['ids'])
|
|
169
|
+
? body['ids'].map(id => ({ id }))
|
|
170
|
+
: [];
|
|
171
|
+
if (!items.length)
|
|
172
|
+
throw new PatternMockError(400, { message: 'Chưa chọn bản ghi nào.' });
|
|
173
|
+
const results = items.map(item => {
|
|
174
|
+
const id = String(item['id'] ?? '');
|
|
175
|
+
try {
|
|
176
|
+
if (action === 'delete')
|
|
177
|
+
this.#delete(resource, id);
|
|
178
|
+
else
|
|
179
|
+
this.#act(resource, id, action, item);
|
|
180
|
+
return { id, ok: true };
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
return { id, ok: false, message: error instanceof PatternMockError ? error.body.message : 'Lỗi không xác định.' };
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
return { results };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Park–Miller generator: the same sequence for the same seed, so seeded records and e2e stay stable. */
|
|
191
|
+
function createPrng(seed) {
|
|
192
|
+
let state = seed;
|
|
193
|
+
return () => {
|
|
194
|
+
state = (state * 16807) % 2147483647;
|
|
195
|
+
return state / 2147483647;
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/** Picks one item with the generator. */
|
|
199
|
+
const pickWith = (random) => (items) => items[Math.floor(random() * items.length)];
|
|
200
|
+
|
|
201
|
+
/** Vietnamese person names shared by the seeds, so an order's customer is a customer of the customer seed. */
|
|
202
|
+
const PERSON_NAMES = [
|
|
203
|
+
'Nguyễn An',
|
|
204
|
+
'Trần Bình',
|
|
205
|
+
'Lê Chi',
|
|
206
|
+
'Phạm Dũng',
|
|
207
|
+
'Hoàng Giang',
|
|
208
|
+
'Vũ Hà',
|
|
209
|
+
'Đặng Khoa',
|
|
210
|
+
'Bùi Lan',
|
|
211
|
+
'Đỗ Minh',
|
|
212
|
+
'Hồ Ngọc',
|
|
213
|
+
'Ngô Phúc',
|
|
214
|
+
'Dương Quân',
|
|
215
|
+
'Lý Sơn',
|
|
216
|
+
'Mai Thảo',
|
|
217
|
+
'Trịnh Uyên',
|
|
218
|
+
'Phan Vy',
|
|
219
|
+
];
|
|
220
|
+
const COMPANY_NAMES = [
|
|
221
|
+
'Công ty TNHH Minh Phát',
|
|
222
|
+
'Công ty CP Thực phẩm Sao Việt',
|
|
223
|
+
'Công ty TNHH Bình Minh',
|
|
224
|
+
'Siêu thị Hoà Bình',
|
|
225
|
+
'Công ty CP Phân phối Đông Á',
|
|
226
|
+
'Công ty TNHH An Khang',
|
|
227
|
+
'Chuỗi cửa hàng Tiện Lợi 24h',
|
|
228
|
+
'Công ty CP Thương mại Hưng Thịnh',
|
|
229
|
+
];
|
|
230
|
+
/** `nguyen.an` from `Nguyễn An`: lowercase ASCII for sample e-mails. */
|
|
231
|
+
function slug(name) {
|
|
232
|
+
return name
|
|
233
|
+
.normalize('NFD')
|
|
234
|
+
.replace(/[̀-ͯ]/g, '')
|
|
235
|
+
.replace(/đ/g, 'd')
|
|
236
|
+
.replace(/Đ/g, 'D')
|
|
237
|
+
.toLowerCase()
|
|
238
|
+
.replace(/[^a-z0-9]+/g, '.')
|
|
239
|
+
.replace(/^\.|\.$/g, '');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const TITLES = [
|
|
243
|
+
'Thanh toán tiền thuê kho',
|
|
244
|
+
'Tạm ứng công tác',
|
|
245
|
+
'Mua văn phòng phẩm',
|
|
246
|
+
'Thanh toán nhà cung cấp',
|
|
247
|
+
'Chi phí quảng cáo',
|
|
248
|
+
'Sửa chữa xe giao hàng',
|
|
249
|
+
'Mua thiết bị IT',
|
|
250
|
+
'Chi phí tiếp khách',
|
|
251
|
+
];
|
|
252
|
+
const DEPARTMENTS = ['Kinh doanh', 'Kho vận', 'Kế toán', 'Marketing', 'Hành chính'];
|
|
253
|
+
const decide = (current, status, reason) => {
|
|
254
|
+
if (current.status !== 'pending')
|
|
255
|
+
throw new PatternMockError(409, { message: `${current.code} đã được xử lý.` });
|
|
256
|
+
return { ...current, status, reason };
|
|
257
|
+
};
|
|
258
|
+
/** `approvals`: 30 đề nghị thanh toán, 18 đang chờ duyệt. Actions `approve`, `reject` (reason). */
|
|
259
|
+
const APPROVAL_RESOURCE = {
|
|
260
|
+
name: 'approvals',
|
|
261
|
+
fieldTypes: { submittedAt: 'date' },
|
|
262
|
+
seed: () => {
|
|
263
|
+
const random = createPrng(20261104);
|
|
264
|
+
const pick = pickWith(random);
|
|
265
|
+
return Array.from({ length: 30 }, (_, index) => {
|
|
266
|
+
const submitted = new Date(2026, 9, 24, 17 - (index % 8), 0);
|
|
267
|
+
submitted.setDate(24 - Math.floor(index / 3));
|
|
268
|
+
const status = index < 18 ? 'pending' : index % 2 === 0 ? 'approved' : 'rejected';
|
|
269
|
+
return {
|
|
270
|
+
id: String(index + 1),
|
|
271
|
+
code: `ĐN-${String(130 - index).padStart(4, '0')}`,
|
|
272
|
+
title: pick(TITLES),
|
|
273
|
+
requester: pick(PERSON_NAMES),
|
|
274
|
+
department: pick(DEPARTMENTS),
|
|
275
|
+
amount: Math.round((500_000 + random() * 49_500_000) / 1000) * 1000,
|
|
276
|
+
submittedAt: submitted.toISOString(),
|
|
277
|
+
status,
|
|
278
|
+
reason: status === 'rejected' ? 'Thiếu chứng từ.' : null,
|
|
279
|
+
note: index % 4 === 0 ? 'Cần thanh toán trước cuối tháng.' : null,
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
actions: {
|
|
284
|
+
approve: current => decide(current, 'approved', null),
|
|
285
|
+
reject: (current, body) => {
|
|
286
|
+
const reason = typeof body['reason'] === 'string' ? body['reason'].trim() : '';
|
|
287
|
+
if (!reason)
|
|
288
|
+
throw new PatternMockError(400, { message: 'Nhập lý do từ chối.', errors: [{ field: 'reason', message: 'Nhập lý do từ chối.' }] });
|
|
289
|
+
return decide(current, 'rejected', reason);
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
/** Three levels: group → line → sub-line. Ids are the dotted path so the tree reads well in e2e. */
|
|
295
|
+
const TREE = [
|
|
296
|
+
[
|
|
297
|
+
'DU',
|
|
298
|
+
'Đồ uống',
|
|
299
|
+
[
|
|
300
|
+
['DU-NUOC', 'Nước giải khát', ['Nước suối', 'Nước ngọt', 'Nước ép']],
|
|
301
|
+
['DU-CAFE', 'Cà phê & trà', ['Cà phê rang xay', 'Trà túi lọc']],
|
|
302
|
+
],
|
|
303
|
+
],
|
|
304
|
+
[
|
|
305
|
+
'TP',
|
|
306
|
+
'Thực phẩm khô',
|
|
307
|
+
[
|
|
308
|
+
['TP-GAO', 'Gạo & ngũ cốc', ['Gạo', 'Ngũ cốc']],
|
|
309
|
+
['TP-GIAVI', 'Gia vị', ['Nước mắm', 'Nước tương', 'Hạt nêm']],
|
|
310
|
+
['TP-MI', 'Mì & bún khô', []],
|
|
311
|
+
],
|
|
312
|
+
],
|
|
313
|
+
[
|
|
314
|
+
'HMP',
|
|
315
|
+
'Hoá mỹ phẩm',
|
|
316
|
+
[
|
|
317
|
+
['HMP-GIAT', 'Giặt xả', ['Bột giặt', 'Nước xả']],
|
|
318
|
+
['HMP-CN', 'Chăm sóc cá nhân', ['Dầu gội', 'Kem đánh răng']],
|
|
319
|
+
],
|
|
320
|
+
],
|
|
321
|
+
[
|
|
322
|
+
'SUA',
|
|
323
|
+
'Sữa & chế phẩm',
|
|
324
|
+
[
|
|
325
|
+
['SUA-TUOI', 'Sữa tươi', []],
|
|
326
|
+
['SUA-CHUA', 'Sữa chua', []],
|
|
327
|
+
],
|
|
328
|
+
],
|
|
329
|
+
];
|
|
330
|
+
const text$5 = (value) => (typeof value === 'string' ? value.trim() : '');
|
|
331
|
+
function seed$1() {
|
|
332
|
+
const records = [];
|
|
333
|
+
let id = 1;
|
|
334
|
+
for (const [groupCode, groupName, lines] of TREE) {
|
|
335
|
+
const groupId = String(id++);
|
|
336
|
+
records.push({ id: groupId, code: groupCode, name: groupName, parentId: null, status: 'active' });
|
|
337
|
+
for (const [lineCode, lineName, subs] of lines) {
|
|
338
|
+
const lineId = String(id++);
|
|
339
|
+
records.push({ id: lineId, code: lineCode, name: lineName, parentId: groupId, status: 'active' });
|
|
340
|
+
subs.forEach((name, index) => records.push({
|
|
341
|
+
id: String(id++),
|
|
342
|
+
code: `${lineCode}-${index + 1}`,
|
|
343
|
+
name,
|
|
344
|
+
parentId: lineId,
|
|
345
|
+
status: name === 'Nước ép' ? 'inactive' : 'active',
|
|
346
|
+
}));
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return records;
|
|
350
|
+
}
|
|
351
|
+
/** Level of a new category under `parentId` (1 for a root). */
|
|
352
|
+
function levelOf(records, parentId) {
|
|
353
|
+
let level = 1;
|
|
354
|
+
let parent = records.find(record => record.id === parentId);
|
|
355
|
+
while (parent) {
|
|
356
|
+
level++;
|
|
357
|
+
parent = records.find(record => record.id === parent.parentId);
|
|
358
|
+
}
|
|
359
|
+
return level;
|
|
360
|
+
}
|
|
361
|
+
function validate$2(body, records, id) {
|
|
362
|
+
const code = text$5(body['code']).toUpperCase();
|
|
363
|
+
const name = text$5(body['name']);
|
|
364
|
+
const parentId = text$5(body['parentId']) || null;
|
|
365
|
+
const errors = [];
|
|
366
|
+
if (!code)
|
|
367
|
+
errors.push({ field: 'code', message: 'Nhập mã danh mục.' });
|
|
368
|
+
if (!name)
|
|
369
|
+
errors.push({ field: 'name', message: 'Nhập tên danh mục.' });
|
|
370
|
+
if (parentId && !records.some(record => record.id === parentId))
|
|
371
|
+
errors.push({ field: 'parentId', message: 'Danh mục cha không tồn tại.' });
|
|
372
|
+
if (parentId && levelOf(records, parentId) > 3)
|
|
373
|
+
errors.push({ field: 'parentId', message: 'Danh mục chỉ có tối đa 3 cấp.' });
|
|
374
|
+
if (errors.length)
|
|
375
|
+
throw new PatternMockError(400, { message: 'Dữ liệu chưa hợp lệ.', errors });
|
|
376
|
+
if (records.some(record => record.id !== id && record.code === code)) {
|
|
377
|
+
throw new PatternMockError(409, {
|
|
378
|
+
message: 'Mã danh mục đã tồn tại.',
|
|
379
|
+
errors: [{ field: 'code', message: `Mã ${code} đã được dùng.` }],
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
return { code, name, parentId, status: body['status'] === 'inactive' ? 'inactive' : 'active' };
|
|
383
|
+
}
|
|
384
|
+
/** Nested tree for the list: every node with its level and children, roots in seed order. */
|
|
385
|
+
function tree(records) {
|
|
386
|
+
const build = (parentId, level) => records
|
|
387
|
+
.filter(record => record.parentId === parentId)
|
|
388
|
+
.map(record => {
|
|
389
|
+
const children = build(record.id, level + 1);
|
|
390
|
+
return {
|
|
391
|
+
...record,
|
|
392
|
+
level,
|
|
393
|
+
children,
|
|
394
|
+
productCount: children.length ? children.reduce((sum, child) => sum + child.productCount, 0) : 3 + (Number(record.id) % 5),
|
|
395
|
+
};
|
|
396
|
+
});
|
|
397
|
+
return build(null, 1);
|
|
398
|
+
}
|
|
399
|
+
/** `categories`: danh mục ba cấp. `GET categories/tree` trả cây lồng nhau; xoá danh mục còn con bị từ chối (409). */
|
|
400
|
+
const CATEGORY_RESOURCE = {
|
|
401
|
+
name: 'categories',
|
|
402
|
+
seed: seed$1,
|
|
403
|
+
create: (body, records, context) => ({ id: context.nextId('categories'), ...validate$2(body, records) }),
|
|
404
|
+
update: (current, body, records) => ({ ...current, ...validate$2({ ...body, parentId: current.parentId }, records, current.id) }),
|
|
405
|
+
beforeDelete: (current, context) => {
|
|
406
|
+
if (context.collection('categories').some(record => record.parentId === current.id)) {
|
|
407
|
+
throw new PatternMockError(409, { message: `${current.name} còn danh mục con, không xoá được.` });
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
route: (method, segments, _query, _body, context) => method === 'GET' && segments.length === 1 && segments[0] === 'tree'
|
|
411
|
+
? { body: tree(context.collection('categories')) }
|
|
412
|
+
: undefined,
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
/** Customer of order ĐH-2400: inactive, so `order/2400/update` shows a stopped customer loaded by ID. */
|
|
416
|
+
const INACTIVE_CUSTOMER_ID = '4';
|
|
417
|
+
const CITIES = ['Hà Nội', 'TP.HCM', 'Đà Nẵng', 'Cần Thơ', 'Hải Phòng'];
|
|
418
|
+
const STREETS = ['Lê Lợi', 'Trần Hưng Đạo', 'Nguyễn Huệ', 'Hai Bà Trưng', 'Lý Thường Kiệt', 'Phan Chu Trinh'];
|
|
419
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
420
|
+
const text$4 = (value) => (typeof value === 'string' ? value.trim() : '');
|
|
421
|
+
const code = (id) => `KH-${String(id).padStart(4, '0')}`;
|
|
422
|
+
function validate$1(body, records, id) {
|
|
423
|
+
const name = text$4(body['name']);
|
|
424
|
+
const email = text$4(body['email']).toLowerCase();
|
|
425
|
+
const phone = text$4(body['phone']);
|
|
426
|
+
const type = body['type'] === 'business' ? 'business' : 'individual';
|
|
427
|
+
const taxCode = text$4(body['taxCode']) || null;
|
|
428
|
+
const errors = [];
|
|
429
|
+
if (!name)
|
|
430
|
+
errors.push({ field: 'name', message: 'Nhập tên khách hàng.' });
|
|
431
|
+
if (!email || !EMAIL.test(email))
|
|
432
|
+
errors.push({ field: 'email', message: 'Email không hợp lệ.' });
|
|
433
|
+
if (!phone)
|
|
434
|
+
errors.push({ field: 'phone', message: 'Nhập số điện thoại.' });
|
|
435
|
+
if (type === 'business' && !taxCode)
|
|
436
|
+
errors.push({ field: 'taxCode', message: 'Doanh nghiệp cần mã số thuế.' });
|
|
437
|
+
if (errors.length)
|
|
438
|
+
throw new PatternMockError(400, { message: 'Dữ liệu chưa hợp lệ.', errors });
|
|
439
|
+
if (records.some(record => record.id !== id && record.email === email)) {
|
|
440
|
+
throw new PatternMockError(409, {
|
|
441
|
+
message: 'Email đã được dùng.',
|
|
442
|
+
errors: [{ field: 'email', message: `${email} đã thuộc về khách hàng khác.` }],
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
return {
|
|
446
|
+
name,
|
|
447
|
+
email,
|
|
448
|
+
phone,
|
|
449
|
+
type,
|
|
450
|
+
taxCode: type === 'business' ? taxCode : null,
|
|
451
|
+
tier: body['tier'] === 'vip' ? 'vip' : 'standard',
|
|
452
|
+
address: text$4(body['address']),
|
|
453
|
+
status: body['status'] === 'inactive' ? 'inactive' : 'active',
|
|
454
|
+
note: text$4(body['note']) || null,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
/** Card counts under the filters of the list, without the segment the cards choose. */
|
|
458
|
+
function counts$1(records, filters) {
|
|
459
|
+
const matched = records.filter(record => FilterUtilities.match(filters, record));
|
|
460
|
+
return {
|
|
461
|
+
all: matched.length,
|
|
462
|
+
individual: matched.filter(record => record.type === 'individual').length,
|
|
463
|
+
business: matched.filter(record => record.type === 'business').length,
|
|
464
|
+
vip: matched.filter(record => record.tier === 'vip').length,
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* `customers`: 16 individuals named like the order seed (ids 1–16), 8 businesses and 16 more individuals.
|
|
469
|
+
* Extra endpoints: `GET customers/counts`, `GET customers/:id/orders|debts|documents` for the 360° tabs.
|
|
470
|
+
*/
|
|
471
|
+
const CUSTOMER_RESOURCE = {
|
|
472
|
+
name: 'customers',
|
|
473
|
+
fieldTypes: { createdAt: 'date' },
|
|
474
|
+
seed: () => {
|
|
475
|
+
const random = createPrng(20261102);
|
|
476
|
+
const pick = pickWith(random);
|
|
477
|
+
const names = [...PERSON_NAMES, ...COMPANY_NAMES, ...PERSON_NAMES.map(name => `${name} ${pick(['Anh', 'Thu', 'Hải', 'Linh'])}`)];
|
|
478
|
+
return names.map((name, index) => {
|
|
479
|
+
const id = index + 1;
|
|
480
|
+
const business = index >= PERSON_NAMES.length && index < PERSON_NAMES.length + COMPANY_NAMES.length;
|
|
481
|
+
const createdAt = new Date(2026, 9, 24 - index * 3, 9, 0);
|
|
482
|
+
return {
|
|
483
|
+
id: String(id),
|
|
484
|
+
code: code(id),
|
|
485
|
+
name,
|
|
486
|
+
type: business ? 'business' : 'individual',
|
|
487
|
+
tier: random() < 0.25 ? 'vip' : 'standard',
|
|
488
|
+
email: `${slug(name)}${business ? '@congty.vn' : '@mail.vn'}`,
|
|
489
|
+
phone: `09${String(Math.floor(random() * 1e8)).padStart(8, '0')}`,
|
|
490
|
+
address: `${10 + Math.floor(random() * 190)} ${pick(STREETS)}, ${pick(CITIES)}`,
|
|
491
|
+
taxCode: business ? `0${String(310000000 + id * 7919)}` : null,
|
|
492
|
+
status: String(id) === INACTIVE_CUSTOMER_ID || id % 11 === 0 ? 'inactive' : 'active',
|
|
493
|
+
debt: random() < 0.4 ? Math.round((random() * 50_000_000) / 1000) * 1000 : 0,
|
|
494
|
+
createdAt: createdAt.toISOString(),
|
|
495
|
+
note: id % 5 === 0 ? 'Ưu tiên giao buổi sáng.' : null,
|
|
496
|
+
};
|
|
497
|
+
});
|
|
498
|
+
},
|
|
499
|
+
create: (body, records, context) => {
|
|
500
|
+
const id = context.nextId('customers');
|
|
501
|
+
return { id, code: code(Number(id)), debt: 0, createdAt: context.now().toISOString(), ...validate$1(body, records) };
|
|
502
|
+
},
|
|
503
|
+
update: (current, body, records) => ({ ...current, ...validate$1(body, records, current.id) }),
|
|
504
|
+
beforeDelete: (current, context) => {
|
|
505
|
+
if (context.collection('orders').some(order => order.customerId === current.id)) {
|
|
506
|
+
throw new PatternMockError(409, { message: `${current.name} còn đơn hàng, không xoá được.` });
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
route: (method, segments, query, _body, context) => {
|
|
510
|
+
if (method !== 'GET')
|
|
511
|
+
return undefined;
|
|
512
|
+
if (segments.length === 1 && segments[0] === 'counts') {
|
|
513
|
+
const filters = JSON.parse(query.get('filters') ?? '[]');
|
|
514
|
+
return { body: counts$1(context.collection('customers'), filters) };
|
|
515
|
+
}
|
|
516
|
+
if (segments.length !== 2)
|
|
517
|
+
return undefined;
|
|
518
|
+
const [id, tab] = segments;
|
|
519
|
+
const customer = context.collection('customers').find(record => record.id === id);
|
|
520
|
+
if (!customer)
|
|
521
|
+
throw new PatternMockError(404, { message: 'Không tìm thấy khách hàng.' });
|
|
522
|
+
const orders = context.collection('orders').filter(order => order.customerId === id);
|
|
523
|
+
if (tab === 'orders') {
|
|
524
|
+
const items = orders.map(order => ({
|
|
525
|
+
id: order.id,
|
|
526
|
+
code: order.code,
|
|
527
|
+
createdAt: order.createdAt,
|
|
528
|
+
total: order.total,
|
|
529
|
+
status: order.status,
|
|
530
|
+
}));
|
|
531
|
+
return { body: { items, total: items.length } };
|
|
532
|
+
}
|
|
533
|
+
if (tab === 'debts') {
|
|
534
|
+
const items = orders
|
|
535
|
+
.filter(order => order.status === 'done')
|
|
536
|
+
.slice(0, customer.debt ? 4 : 0)
|
|
537
|
+
.map((order, index) => ({
|
|
538
|
+
id: order.id,
|
|
539
|
+
orderCode: order.code,
|
|
540
|
+
dueDate: new Date(new Date(order.createdAt).getTime() + (15 + index * 15) * 86_400_000).toISOString(),
|
|
541
|
+
amount: Math.round(order.total / 2 / 1000) * 1000,
|
|
542
|
+
}));
|
|
543
|
+
return { body: { items, total: items.length } };
|
|
544
|
+
}
|
|
545
|
+
if (tab === 'documents') {
|
|
546
|
+
const kinds = customer.type === 'business'
|
|
547
|
+
? ['Hợp đồng nguyên tắc', 'Giấy phép kinh doanh', 'Biên bản đối chiếu công nợ']
|
|
548
|
+
: ['Hợp đồng mua bán', 'CCCD'];
|
|
549
|
+
const items = Number(id) % 3 === 0 ? [] : kinds.map((name, index) => ({ id: `${id}-${index + 1}`, name, size: 120_000 + index * 48_000 }));
|
|
550
|
+
return { body: { items, total: items.length } };
|
|
551
|
+
}
|
|
552
|
+
return undefined;
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
const CHANNELS = ['Online', 'Cửa hàng', 'Đại lý'];
|
|
557
|
+
const WAREHOUSES = ['Hà Nội', 'TP.HCM', 'Đà Nẵng'];
|
|
558
|
+
const PAYMENTS = ['Tiền mặt', 'Chuyển khoản', 'COD'];
|
|
559
|
+
const SOURCES = ['Website', 'Ứng dụng', 'Hotline', 'Sàn TMĐT'];
|
|
560
|
+
const CREATORS = ['Nguyễn An', 'Bùi Lan', 'Đỗ Minh'];
|
|
561
|
+
/** Số lượng tối đa một dòng; vượt thì API báo lỗi ngay trên dòng (`lines.<index>.quantity`). */
|
|
562
|
+
const STOCK = 50;
|
|
563
|
+
const ACTOR = 'Người dùng mẫu';
|
|
564
|
+
const STATUS_NAME = {
|
|
565
|
+
pending: 'Chờ xác nhận',
|
|
566
|
+
shipping: 'Đang giao',
|
|
567
|
+
done: 'Hoàn tất',
|
|
568
|
+
cancelled: 'Đã huỷ',
|
|
569
|
+
};
|
|
570
|
+
const text$3 = (value) => (typeof value === 'string' ? value.trim() : '');
|
|
571
|
+
const fail = (message) => {
|
|
572
|
+
throw new PatternMockError(409, { message });
|
|
573
|
+
};
|
|
574
|
+
/**
|
|
575
|
+
* 128 orders as doc 08: Park–Miller seed 20261024, codes ĐH-2400 down, four a day back from 24/10/2026. The random
|
|
576
|
+
* calls happen in the order of the doc (status, customer, channel, total, warehouse, payment) so the list matches the
|
|
577
|
+
* E1 screen; lines, approval and the other fields come from a second generator.
|
|
578
|
+
*/
|
|
579
|
+
function seed() {
|
|
580
|
+
const random = createPrng(20261024);
|
|
581
|
+
const pick = pickWith(random);
|
|
582
|
+
const extra = createPrng(20261103);
|
|
583
|
+
const pickExtra = pickWith(extra);
|
|
584
|
+
const start = new Date(2026, 9, 24, 8, 0);
|
|
585
|
+
return Array.from({ length: 128 }, (_, index) => {
|
|
586
|
+
const roll = random();
|
|
587
|
+
const status = index < 3
|
|
588
|
+
? ['pending', 'shipping', 'done'][index]
|
|
589
|
+
: roll < 0.1
|
|
590
|
+
? 'pending'
|
|
591
|
+
: roll < 0.36
|
|
592
|
+
? 'shipping'
|
|
593
|
+
: roll < 0.94
|
|
594
|
+
? 'done'
|
|
595
|
+
: 'cancelled';
|
|
596
|
+
const customerIndex = PERSON_NAMES.indexOf(pick(PERSON_NAMES));
|
|
597
|
+
const channel = pick(CHANNELS);
|
|
598
|
+
const total = Math.round((150_000 + random() * 14_850_000) / 1000) * 1000;
|
|
599
|
+
const warehouse = pick(WAREHOUSES);
|
|
600
|
+
const payment = pick(PAYMENTS);
|
|
601
|
+
const createdAt = new Date(start);
|
|
602
|
+
createdAt.setDate(start.getDate() - Math.floor(index / 4));
|
|
603
|
+
createdAt.setHours(8 + (index % 4) * 2);
|
|
604
|
+
// Order ĐH-2400 belongs to the inactive customer: its update shows a stopped customer loaded by ID.
|
|
605
|
+
const customerId = index === 0 ? INACTIVE_CUSTOMER_ID : String(customerIndex + 1);
|
|
606
|
+
const approval = status === 'pending' ? (index % 3 === 1 ? 'submitted' : 'draft') : status === 'cancelled' ? 'rejected' : 'approved';
|
|
607
|
+
const lines = splitTotal(total, extra);
|
|
608
|
+
const delivered = status === 'done' ? new Date(createdAt.getTime() + (1 + Math.floor(extra() * 4)) * 86_400_000).toISOString() : null;
|
|
609
|
+
return {
|
|
610
|
+
id: String(2400 - index),
|
|
611
|
+
code: `ĐH-${2400 - index}`,
|
|
612
|
+
customerId,
|
|
613
|
+
customer: PERSON_NAMES[Number(customerId) - 1],
|
|
614
|
+
channel,
|
|
615
|
+
warehouse,
|
|
616
|
+
payment,
|
|
617
|
+
createdAt: createdAt.toISOString(),
|
|
618
|
+
deliveredAt: delivered,
|
|
619
|
+
total,
|
|
620
|
+
status,
|
|
621
|
+
approval,
|
|
622
|
+
approvalHistory: history(approval, createdAt, index),
|
|
623
|
+
lines,
|
|
624
|
+
creator: pickExtra(CREATORS),
|
|
625
|
+
source: pickExtra(SOURCES),
|
|
626
|
+
tracking: status === 'shipping' || status === 'done' ? `VD${String(880000 + index * 37)}` : null,
|
|
627
|
+
note: index % 6 === 0 ? 'Gọi trước khi giao.' : null,
|
|
628
|
+
cancelReason: status === 'cancelled' ? 'Khách đổi ý.' : null,
|
|
629
|
+
};
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
/** One to three lines of the 36 seeded products; the last line takes what is left, so they add up to the total. */
|
|
633
|
+
function splitTotal(total, random) {
|
|
634
|
+
const count = 1 + Math.floor(random() * 3);
|
|
635
|
+
const result = [];
|
|
636
|
+
let left = total;
|
|
637
|
+
for (let line = 0; line < count - 1; line++) {
|
|
638
|
+
const quantity = 1 + Math.floor(random() * 4);
|
|
639
|
+
const unitPrice = Math.max(1000, Math.round((total * (0.15 + random() * 0.15)) / quantity / 1000) * 1000);
|
|
640
|
+
result.push({ productId: String(1 + Math.floor(random() * 36)), quantity, unitPrice });
|
|
641
|
+
left -= quantity * unitPrice;
|
|
642
|
+
}
|
|
643
|
+
result.push({ productId: String(1 + Math.floor(random() * 36)), quantity: 1, unitPrice: left });
|
|
644
|
+
return result;
|
|
645
|
+
}
|
|
646
|
+
function history(approval, createdAt, index) {
|
|
647
|
+
if (approval === 'draft')
|
|
648
|
+
return [];
|
|
649
|
+
const submitted = {
|
|
650
|
+
action: 'submit',
|
|
651
|
+
by: CREATORS[index % CREATORS.length],
|
|
652
|
+
at: new Date(createdAt.getTime() + 3_600_000).toISOString(),
|
|
653
|
+
};
|
|
654
|
+
if (approval === 'submitted')
|
|
655
|
+
return [submitted];
|
|
656
|
+
const decidedAt = new Date(createdAt.getTime() + 7_200_000).toISOString();
|
|
657
|
+
return approval === 'approved'
|
|
658
|
+
? [submitted, { action: 'approve', by: 'Trần Bình', at: decidedAt }]
|
|
659
|
+
: [submitted, { action: 'reject', by: 'Trần Bình', at: decidedAt, reason: 'Khách đổi ý.' }];
|
|
660
|
+
}
|
|
661
|
+
/** Validates and prices the lines like a real API: a line error names its field (`lines.<index>.<field>`). */
|
|
662
|
+
function lines(body, context, current) {
|
|
663
|
+
const raw = Array.isArray(body['lines']) ? body['lines'] : [];
|
|
664
|
+
const products = context.collection('products');
|
|
665
|
+
const errors = [];
|
|
666
|
+
if (!raw.length)
|
|
667
|
+
errors.push({ field: 'lines', message: 'Thêm ít nhất một dòng hàng.' });
|
|
668
|
+
const result = raw.map((line, index) => {
|
|
669
|
+
const productId = text$3(line['productId']);
|
|
670
|
+
const quantity = Number(line['quantity']);
|
|
671
|
+
const product = products.find(item => item.id === productId);
|
|
672
|
+
const kept = current?.some(item => item.productId === productId);
|
|
673
|
+
if (!product)
|
|
674
|
+
errors.push({ field: `lines.${index}.productId`, message: 'Chọn sản phẩm.' });
|
|
675
|
+
else if (product.status === 'inactive' && !kept)
|
|
676
|
+
errors.push({ field: `lines.${index}.productId`, message: `${product.name} đã ngừng kinh doanh.` });
|
|
677
|
+
if (!Number.isInteger(quantity) || quantity < 1)
|
|
678
|
+
errors.push({ field: `lines.${index}.quantity`, message: 'Số lượng phải là số nguyên dương.' });
|
|
679
|
+
else if (quantity > STOCK)
|
|
680
|
+
errors.push({ field: `lines.${index}.quantity`, message: `Vượt tồn kho (còn ${STOCK}).` });
|
|
681
|
+
const unitPrice = Number(line['unitPrice']);
|
|
682
|
+
return { productId, quantity, unitPrice: Number.isFinite(unitPrice) && unitPrice >= 0 ? unitPrice : (product?.price ?? 0) };
|
|
683
|
+
});
|
|
684
|
+
if (errors.length)
|
|
685
|
+
throw new PatternMockError(400, { message: 'Dữ liệu chưa hợp lệ.', errors });
|
|
686
|
+
return result;
|
|
687
|
+
}
|
|
688
|
+
function header(body, context, current) {
|
|
689
|
+
const customerId = text$3(body['customerId']);
|
|
690
|
+
const customer = context.collection('customers').find(item => item.id === customerId);
|
|
691
|
+
const errors = [];
|
|
692
|
+
if (!customer)
|
|
693
|
+
errors.push({ field: 'customerId', message: 'Chọn khách hàng.' });
|
|
694
|
+
else if (customer.status === 'inactive' && customer.id !== current?.customerId) {
|
|
695
|
+
errors.push({ field: 'customerId', message: `${customer.name} đã ngừng hoạt động.` });
|
|
696
|
+
}
|
|
697
|
+
if (errors.length)
|
|
698
|
+
throw new PatternMockError(400, { message: 'Dữ liệu chưa hợp lệ.', errors });
|
|
699
|
+
const pickOf = (values, value) => (values.includes(value) ? value : values[0]);
|
|
700
|
+
return {
|
|
701
|
+
customerId,
|
|
702
|
+
customer: current?.customerId === customerId ? current.customer : customer.name,
|
|
703
|
+
channel: pickOf(CHANNELS, body['channel']),
|
|
704
|
+
warehouse: pickOf(WAREHOUSES, body['warehouse']),
|
|
705
|
+
payment: pickOf(PAYMENTS, body['payment']),
|
|
706
|
+
note: text$3(body['note']) || null,
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
const sum = (orderLines) => orderLines.reduce((total, line) => total + line.quantity * line.unitPrice, 0);
|
|
710
|
+
const step = (action, reason) => ({
|
|
711
|
+
action,
|
|
712
|
+
by: ACTOR,
|
|
713
|
+
at: new Date().toISOString(),
|
|
714
|
+
...(reason ? { reason } : {}),
|
|
715
|
+
});
|
|
716
|
+
/** Tab and card counts under the filters of the list, without the status the tabs choose. */
|
|
717
|
+
function counts(records, filters) {
|
|
718
|
+
const matched = records.filter(record => FilterUtilities.match(filters, record, { fieldTypes: { createdAt: 'date', deliveredAt: 'date' } }));
|
|
719
|
+
const of = (status) => matched.filter(record => record.status === status);
|
|
720
|
+
return {
|
|
721
|
+
all: matched.length,
|
|
722
|
+
pending: of('pending').length,
|
|
723
|
+
shipping: of('shipping').length,
|
|
724
|
+
done: of('done').length,
|
|
725
|
+
cancelled: of('cancelled').length,
|
|
726
|
+
revenue: of('done').reduce((total, record) => total + record.total, 0),
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* `orders`: chứng từ có dòng hàng và quy trình duyệt. Actions: `confirm`, `cancel` (reason), `submit`, `approve`,
|
|
731
|
+
* `reject` (reason), one by one or in bulk; a record in the wrong state fails alone. `GET orders/counts` for tabs and cards.
|
|
732
|
+
*/
|
|
733
|
+
const ORDER_RESOURCE = {
|
|
734
|
+
name: 'orders',
|
|
735
|
+
fieldTypes: { createdAt: 'date', deliveredAt: 'date' },
|
|
736
|
+
seed,
|
|
737
|
+
create: (body, _records, context) => {
|
|
738
|
+
const head = header(body, context);
|
|
739
|
+
const orderLines = lines(body, context);
|
|
740
|
+
const id = String(Math.max(2400, ...context.collection('orders').map(order => Number(order.id) || 0)) + 1);
|
|
741
|
+
return {
|
|
742
|
+
id,
|
|
743
|
+
code: `ĐH-${id}`,
|
|
744
|
+
...head,
|
|
745
|
+
createdAt: context.now().toISOString(),
|
|
746
|
+
deliveredAt: null,
|
|
747
|
+
total: sum(orderLines),
|
|
748
|
+
status: 'pending',
|
|
749
|
+
approval: 'draft',
|
|
750
|
+
approvalHistory: [],
|
|
751
|
+
lines: orderLines,
|
|
752
|
+
creator: ACTOR,
|
|
753
|
+
source: 'Website',
|
|
754
|
+
tracking: null,
|
|
755
|
+
cancelReason: null,
|
|
756
|
+
};
|
|
757
|
+
},
|
|
758
|
+
update: (current, body, _records, context) => {
|
|
759
|
+
if (current.status !== 'pending' || current.approval === 'submitted' || current.approval === 'approved') {
|
|
760
|
+
fail(`Đơn ${current.code} đã gửi duyệt hoặc đã xử lý, không cập nhật được.`);
|
|
761
|
+
}
|
|
762
|
+
const orderLines = lines(body, context, current.lines);
|
|
763
|
+
return { ...current, ...header(body, context, current), lines: orderLines, total: sum(orderLines) };
|
|
764
|
+
},
|
|
765
|
+
actions: {
|
|
766
|
+
confirm: current => {
|
|
767
|
+
if (current.status !== 'pending')
|
|
768
|
+
fail(`${current.code} ở trạng thái "${STATUS_NAME[current.status]}", không xác nhận được.`);
|
|
769
|
+
return { ...current, status: 'shipping', tracking: current.tracking ?? `VD${current.id}` };
|
|
770
|
+
},
|
|
771
|
+
cancel: (current, body) => {
|
|
772
|
+
const reason = text$3(body['reason']);
|
|
773
|
+
if (!reason)
|
|
774
|
+
throw new PatternMockError(400, { message: 'Nhập lý do huỷ.', errors: [{ field: 'reason', message: 'Nhập lý do huỷ.' }] });
|
|
775
|
+
if (current.status === 'done' || current.status === 'cancelled')
|
|
776
|
+
fail(`${current.code} ở trạng thái "${STATUS_NAME[current.status]}", không huỷ được.`);
|
|
777
|
+
return { ...current, status: 'cancelled', cancelReason: reason };
|
|
778
|
+
},
|
|
779
|
+
submit: current => {
|
|
780
|
+
if (current.approval !== 'draft' && current.approval !== 'rejected')
|
|
781
|
+
fail(`${current.code} đã gửi duyệt.`);
|
|
782
|
+
return { ...current, approval: 'submitted', approvalHistory: [...current.approvalHistory, step('submit')] };
|
|
783
|
+
},
|
|
784
|
+
approve: current => {
|
|
785
|
+
if (current.approval !== 'submitted')
|
|
786
|
+
fail(`${current.code} không chờ duyệt.`);
|
|
787
|
+
return { ...current, approval: 'approved', approvalHistory: [...current.approvalHistory, step('approve')] };
|
|
788
|
+
},
|
|
789
|
+
reject: (current, body) => {
|
|
790
|
+
const reason = text$3(body['reason']);
|
|
791
|
+
if (!reason)
|
|
792
|
+
throw new PatternMockError(400, { message: 'Nhập lý do từ chối.', errors: [{ field: 'reason', message: 'Nhập lý do từ chối.' }] });
|
|
793
|
+
if (current.approval !== 'submitted')
|
|
794
|
+
fail(`${current.code} không chờ duyệt.`);
|
|
795
|
+
return { ...current, approval: 'rejected', approvalHistory: [...current.approvalHistory, step('reject', reason)] };
|
|
796
|
+
},
|
|
797
|
+
},
|
|
798
|
+
route: (method, segments, query, _body, context) => {
|
|
799
|
+
if (method === 'GET' && segments.length === 1 && segments[0] === 'counts') {
|
|
800
|
+
const filters = JSON.parse(query.get('filters') ?? '[]');
|
|
801
|
+
return { body: counts(context.collection('orders'), filters) };
|
|
802
|
+
}
|
|
803
|
+
return undefined;
|
|
804
|
+
},
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
const text$2 = (value) => (typeof value === 'string' ? value.trim() : '');
|
|
808
|
+
/**
|
|
809
|
+
* `partners`: đối tác của flow tạo nhiều bước. `GET partners/check-code?code=` trả `{ available }` để kiểm tra trùng mã
|
|
810
|
+
* khi chuyển bước; `POST partners` kiểm tra lại (409 nếu trùng).
|
|
811
|
+
*/
|
|
812
|
+
const PARTNER_RESOURCE = {
|
|
813
|
+
name: 'partners',
|
|
814
|
+
seed: () => [...PERSON_NAMES.slice(0, 5), ...COMPANY_NAMES.slice(0, 5)].map((name, index) => ({
|
|
815
|
+
id: String(index + 1),
|
|
816
|
+
code: `DT-${String(index + 1).padStart(3, '0')}`,
|
|
817
|
+
type: index < 5 ? 'individual' : 'business',
|
|
818
|
+
name,
|
|
819
|
+
identity: index < 5 ? `0790${String(index).padStart(8, '0')}` : `0${String(310100000 + index)}`,
|
|
820
|
+
representative: index < 5 ? null : PERSON_NAMES[index],
|
|
821
|
+
email: `doitac${index + 1}@mail.vn`,
|
|
822
|
+
phone: `0912${String(100000 + index).padStart(6, '0')}`,
|
|
823
|
+
address: 'TP.HCM',
|
|
824
|
+
})),
|
|
825
|
+
create: (body, records, context) => {
|
|
826
|
+
const code = text$2(body['code']).toUpperCase();
|
|
827
|
+
const type = body['type'] === 'business' ? 'business' : 'individual';
|
|
828
|
+
const errors = [];
|
|
829
|
+
for (const field of ['code', 'name', 'identity', 'email', 'phone']) {
|
|
830
|
+
if (!text$2(body[field]))
|
|
831
|
+
errors.push({ field, message: 'Bắt buộc nhập.' });
|
|
832
|
+
}
|
|
833
|
+
if (type === 'business' && !text$2(body['representative']))
|
|
834
|
+
errors.push({ field: 'representative', message: 'Bắt buộc nhập.' });
|
|
835
|
+
if (errors.length)
|
|
836
|
+
throw new PatternMockError(400, { message: 'Dữ liệu chưa hợp lệ.', errors });
|
|
837
|
+
if (records.some(record => record.code === code)) {
|
|
838
|
+
throw new PatternMockError(409, {
|
|
839
|
+
message: 'Mã đối tác đã tồn tại.',
|
|
840
|
+
errors: [{ field: 'code', message: `Mã ${code} đã được dùng.` }],
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
return {
|
|
844
|
+
id: context.nextId('partners'),
|
|
845
|
+
code,
|
|
846
|
+
type,
|
|
847
|
+
name: text$2(body['name']),
|
|
848
|
+
identity: text$2(body['identity']),
|
|
849
|
+
representative: type === 'business' ? text$2(body['representative']) : null,
|
|
850
|
+
email: text$2(body['email']),
|
|
851
|
+
phone: text$2(body['phone']),
|
|
852
|
+
address: text$2(body['address']),
|
|
853
|
+
};
|
|
854
|
+
},
|
|
855
|
+
route: (method, segments, query, _body, context) => {
|
|
856
|
+
if (method !== 'GET' || segments.length !== 1 || segments[0] !== 'check-code')
|
|
857
|
+
return undefined;
|
|
858
|
+
const code = (query.get('code') ?? '').trim().toUpperCase();
|
|
859
|
+
return { body: { available: !!code && !context.collection('partners').some(record => record.code === code) } };
|
|
860
|
+
},
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
const NAMES = [
|
|
864
|
+
'Nước suối 500ml',
|
|
865
|
+
'Sữa tươi 1L',
|
|
866
|
+
'Mì gói hảo hạng',
|
|
867
|
+
'Gạo thơm 5kg',
|
|
868
|
+
'Dầu ăn 1L',
|
|
869
|
+
'Nước mắm 500ml',
|
|
870
|
+
'Đường tinh luyện 1kg',
|
|
871
|
+
'Cà phê rang xay 500g',
|
|
872
|
+
'Trà xanh 100 gói',
|
|
873
|
+
'Bánh quy bơ',
|
|
874
|
+
'Nước ngọt 330ml',
|
|
875
|
+
'Bột giặt 3kg',
|
|
876
|
+
'Nước rửa chén 750ml',
|
|
877
|
+
'Khăn giấy 10 gói',
|
|
878
|
+
'Kem đánh răng',
|
|
879
|
+
'Dầu gội 650ml',
|
|
880
|
+
'Sữa chua 4 hộp',
|
|
881
|
+
'Bánh mì sandwich',
|
|
882
|
+
'Xúc xích 500g',
|
|
883
|
+
'Trứng gà 10 quả',
|
|
884
|
+
'Nước tương 500ml',
|
|
885
|
+
'Hạt nêm 900g',
|
|
886
|
+
'Bia lon 330ml',
|
|
887
|
+
'Ngũ cốc 400g',
|
|
888
|
+
'Sữa đặc 380g',
|
|
889
|
+
'Bánh gạo',
|
|
890
|
+
'Snack khoai tây',
|
|
891
|
+
'Kẹo dẻo trái cây',
|
|
892
|
+
'Nước cam ép 1L',
|
|
893
|
+
'Bột mì 1kg',
|
|
894
|
+
'Muối i-ốt 500g',
|
|
895
|
+
'Tương ớt 250g',
|
|
896
|
+
'Mật ong 500ml',
|
|
897
|
+
'Hạt điều rang 250g',
|
|
898
|
+
'Sốt mayonnaise',
|
|
899
|
+
'Phô mai lát',
|
|
900
|
+
];
|
|
901
|
+
const UNITS = ['Chai', 'Hộp', 'Gói', 'Thùng', 'Cái'];
|
|
902
|
+
const text$1 = (value) => (typeof value === 'string' ? value.trim() : '');
|
|
903
|
+
/** Validates a create/update body like a real API would: required fields, then a unique code. */
|
|
904
|
+
function validate(body, records, id) {
|
|
905
|
+
const code = text$1(body['code']);
|
|
906
|
+
const name = text$1(body['name']);
|
|
907
|
+
const unit = text$1(body['unit']);
|
|
908
|
+
const price = Number(body['price']);
|
|
909
|
+
const status = body['status'] === 'inactive' ? 'inactive' : 'active';
|
|
910
|
+
const errors = [];
|
|
911
|
+
if (!code)
|
|
912
|
+
errors.push({ field: 'code', message: 'Nhập mã sản phẩm.' });
|
|
913
|
+
if (!name)
|
|
914
|
+
errors.push({ field: 'name', message: 'Nhập tên sản phẩm.' });
|
|
915
|
+
if (!Number.isFinite(price) || price < 0)
|
|
916
|
+
errors.push({ field: 'price', message: 'Giá bán phải là số không âm.' });
|
|
917
|
+
if (errors.length)
|
|
918
|
+
throw new PatternMockError(400, { message: 'Dữ liệu chưa hợp lệ.', errors });
|
|
919
|
+
if (records.some(record => record.id !== id && record.code.toLowerCase() === code.toLowerCase())) {
|
|
920
|
+
throw new PatternMockError(409, {
|
|
921
|
+
message: 'Mã sản phẩm đã tồn tại.',
|
|
922
|
+
errors: [{ field: 'code', message: `Mã ${code} đã được dùng cho sản phẩm khác.` }],
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
return { code, name, unit: unit || 'Cái', price, status };
|
|
926
|
+
}
|
|
927
|
+
/** Classifies each row of an import: new, duplicate of a stored code, or invalid. */
|
|
928
|
+
function preview(rows, records) {
|
|
929
|
+
const seen = new Set();
|
|
930
|
+
return rows.map((row, index) => {
|
|
931
|
+
const code = text$1(row['code']).toUpperCase();
|
|
932
|
+
const name = text$1(row['name']);
|
|
933
|
+
const price = Number(row['price']);
|
|
934
|
+
const base = { index, code, name, unit: text$1(row['unit']) || 'Cái', price };
|
|
935
|
+
if (!code || !name)
|
|
936
|
+
return { ...base, result: 'invalid', message: 'Thiếu mã hoặc tên.' };
|
|
937
|
+
if (!Number.isFinite(price) || price < 0)
|
|
938
|
+
return { ...base, result: 'invalid', message: 'Giá bán không hợp lệ.' };
|
|
939
|
+
if (seen.has(code))
|
|
940
|
+
return { ...base, result: 'invalid', message: 'Trùng mã trong tệp.' };
|
|
941
|
+
seen.add(code);
|
|
942
|
+
const existing = records.find(record => record.code.toUpperCase() === code);
|
|
943
|
+
return existing ? { ...base, result: 'duplicate', message: `Đã có: ${existing.name}` } : { ...base, result: 'new' };
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* `products`: 36 products, every seventh inactive (used by order lines and the inactive-select case).
|
|
948
|
+
* `POST products/import/preview` classifies rows; `POST products/import` writes them (`duplicates`: skip | overwrite).
|
|
949
|
+
*/
|
|
950
|
+
const PRODUCT_RESOURCE = {
|
|
951
|
+
name: 'products',
|
|
952
|
+
seed: () => {
|
|
953
|
+
const random = createPrng(20261101);
|
|
954
|
+
const pick = pickWith(random);
|
|
955
|
+
return NAMES.map((name, index) => ({
|
|
956
|
+
id: String(index + 1),
|
|
957
|
+
code: `SP-${String(index + 1).padStart(3, '0')}`,
|
|
958
|
+
name,
|
|
959
|
+
status: (index + 1) % 7 === 0 ? 'inactive' : 'active',
|
|
960
|
+
unit: pick(UNITS),
|
|
961
|
+
price: Math.round((8_000 + random() * 392_000) / 1000) * 1000,
|
|
962
|
+
}));
|
|
963
|
+
},
|
|
964
|
+
create: (body, records, context) => ({ id: context.nextId('products'), ...validate(body, records) }),
|
|
965
|
+
// The code is locked after creation: the update keeps the stored one whatever the body says.
|
|
966
|
+
update: (current, body, records) => ({ ...current, ...validate({ ...body, code: current.code }, records, current.id) }),
|
|
967
|
+
route: (method, segments, _query, body, context) => {
|
|
968
|
+
if (method !== 'POST' || segments[0] !== 'import')
|
|
969
|
+
return undefined;
|
|
970
|
+
const records = context.collection('products');
|
|
971
|
+
const rows = preview(Array.isArray(body['rows']) ? body['rows'] : [], records);
|
|
972
|
+
if (segments[1] === 'preview')
|
|
973
|
+
return { body: { rows } };
|
|
974
|
+
if (segments.length !== 1)
|
|
975
|
+
return undefined;
|
|
976
|
+
const overwrite = body['duplicates'] === 'overwrite';
|
|
977
|
+
let next = [...records];
|
|
978
|
+
let created = 0;
|
|
979
|
+
let updated = 0;
|
|
980
|
+
for (const row of rows) {
|
|
981
|
+
const data = { code: row.code, name: row.name, unit: row.unit, price: row.price };
|
|
982
|
+
if (row.result === 'new') {
|
|
983
|
+
next = [
|
|
984
|
+
{ id: String(next.reduce((max, record) => Math.max(max, Number(record.id) || 0), 0) + 1), status: 'active', ...data },
|
|
985
|
+
...next,
|
|
986
|
+
];
|
|
987
|
+
created++;
|
|
988
|
+
}
|
|
989
|
+
else if (row.result === 'duplicate' && overwrite) {
|
|
990
|
+
next = next.map(record => (record.code.toUpperCase() === row.code ? { ...record, ...data, code: record.code } : record));
|
|
991
|
+
updated++;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
context.save('products', next);
|
|
995
|
+
return { body: { created, updated, skipped: rows.length - created - updated } };
|
|
996
|
+
},
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
const text = (value) => (typeof value === 'string' ? value.trim() : '');
|
|
1000
|
+
/** `settings`: one record. `GET settings` reads it, `PUT settings` replaces it. */
|
|
1001
|
+
const SETTINGS_RESOURCE = {
|
|
1002
|
+
name: 'settings',
|
|
1003
|
+
seed: () => [
|
|
1004
|
+
{
|
|
1005
|
+
id: 'default',
|
|
1006
|
+
storeName: 'Cửa hàng mẫu SDCoreJS',
|
|
1007
|
+
hotline: '1900 6868',
|
|
1008
|
+
address: '12 Lê Lợi, Quận 1, TP.HCM',
|
|
1009
|
+
currency: 'VND',
|
|
1010
|
+
orderPrefix: 'ĐH',
|
|
1011
|
+
autoConfirm: false,
|
|
1012
|
+
lowStockThreshold: 10,
|
|
1013
|
+
emailNotify: true,
|
|
1014
|
+
smsNotify: false,
|
|
1015
|
+
notifyEmail: 'vanhanh@cuahang.vn',
|
|
1016
|
+
sessionMinutes: 30,
|
|
1017
|
+
twoFactor: false,
|
|
1018
|
+
updatedAt: new Date(2026, 9, 24, 9, 30).toISOString(),
|
|
1019
|
+
},
|
|
1020
|
+
],
|
|
1021
|
+
route: (method, segments, _query, body, context) => {
|
|
1022
|
+
if (segments.length)
|
|
1023
|
+
return undefined;
|
|
1024
|
+
const current = context.collection('settings')[0];
|
|
1025
|
+
if (method === 'GET')
|
|
1026
|
+
return { body: current };
|
|
1027
|
+
if (method !== 'PUT')
|
|
1028
|
+
return undefined;
|
|
1029
|
+
const errors = [];
|
|
1030
|
+
if (!text(body['storeName']))
|
|
1031
|
+
errors.push({ field: 'storeName', message: 'Nhập tên cửa hàng.' });
|
|
1032
|
+
if (!text(body['orderPrefix']))
|
|
1033
|
+
errors.push({ field: 'orderPrefix', message: 'Nhập tiền tố mã đơn.' });
|
|
1034
|
+
const minutes = Number(body['sessionMinutes']);
|
|
1035
|
+
if (!Number.isInteger(minutes) || minutes < 5 || minutes > 480)
|
|
1036
|
+
errors.push({ field: 'sessionMinutes', message: 'Từ 5 đến 480 phút.' });
|
|
1037
|
+
if (errors.length)
|
|
1038
|
+
throw new PatternMockError(400, { message: 'Dữ liệu chưa hợp lệ.', errors });
|
|
1039
|
+
const updated = {
|
|
1040
|
+
...current,
|
|
1041
|
+
...body,
|
|
1042
|
+
id: current.id,
|
|
1043
|
+
updatedAt: context.now().toISOString(),
|
|
1044
|
+
};
|
|
1045
|
+
context.save('settings', [updated]);
|
|
1046
|
+
return { body: updated };
|
|
1047
|
+
},
|
|
1048
|
+
};
|
|
1049
|
+
|
|
1050
|
+
// why: each resource is typed by its own record; the backend only needs the common shape.
|
|
1051
|
+
const erase = (resource) => resource;
|
|
1052
|
+
/** Every collection the mock API serves. */
|
|
1053
|
+
const PATTERN_MOCK_RESOURCES = [
|
|
1054
|
+
erase(PRODUCT_RESOURCE),
|
|
1055
|
+
erase(CUSTOMER_RESOURCE),
|
|
1056
|
+
erase(ORDER_RESOURCE),
|
|
1057
|
+
erase(APPROVAL_RESOURCE),
|
|
1058
|
+
erase(CATEGORY_RESOURCE),
|
|
1059
|
+
erase(PARTNER_RESOURCE),
|
|
1060
|
+
erase(SETTINGS_RESOURCE),
|
|
1061
|
+
];
|
|
1062
|
+
|
|
1063
|
+
/** Loaded on the first mock request (see `PatternMockApiState.backend()`). */
|
|
1064
|
+
function createPatternMockBackend(storage) {
|
|
1065
|
+
return new PatternMockBackend(PATTERN_MOCK_RESOURCES, storage);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
export { createPatternMockBackend };
|
|
1069
|
+
//# sourceMappingURL=sdcorejs-angular-modules-pattern-mock-backend.factory-S0Vuy6Oc.mjs.map
|