|
| 1 | +import { AutocompleteOption } from '../../../design-system/autocomplete-select/autocomplete-select'; |
| 2 | +import { DSelectOption } from '../design-system/select-option.model'; |
| 3 | + |
| 4 | +/** Estado interno do formulário de criação (campos do POST) */ |
| 5 | +export interface ProductCreateFormState { |
| 6 | + categoryId: string; |
| 7 | + manufacturerId: string; |
| 8 | + partOriginId: string; |
| 9 | + unitId: string; |
| 10 | + internalCode: string; |
| 11 | + barcode: string; |
| 12 | + name: string; |
| 13 | + shortDescription: string; |
| 14 | + description: string; |
| 15 | + weight: number; |
| 16 | + height: number; |
| 17 | + width: number; |
| 18 | + length: number; |
| 19 | + featured: boolean; |
| 20 | +} |
| 21 | + |
| 22 | +export function defaultProductCreateFormState(): ProductCreateFormState { |
| 23 | + return { |
| 24 | + categoryId: '', |
| 25 | + manufacturerId: '', |
| 26 | + partOriginId: '', |
| 27 | + unitId: '', |
| 28 | + internalCode: '', |
| 29 | + barcode: '', |
| 30 | + name: '', |
| 31 | + shortDescription: '', |
| 32 | + description: '', |
| 33 | + weight: 0, |
| 34 | + height: 0, |
| 35 | + width: 0, |
| 36 | + length: 0, |
| 37 | + featured: false, |
| 38 | + }; |
| 39 | +} |
| 40 | + |
| 41 | +export function createFormToGeneralSource(state: ProductCreateFormState): ProductGeneralFormSource { |
| 42 | + return { |
| 43 | + ...state, |
| 44 | + slug: '', |
| 45 | + statusId: '', |
| 46 | + active: true, |
| 47 | + }; |
| 48 | +} |
| 49 | + |
| 50 | +/** Payload esperado pelo backend no POST /product */ |
| 51 | +export interface CreateProductPayload { |
| 52 | + category_id: string; |
| 53 | + manufacturer_id: string; |
| 54 | + part_origin_id: string; |
| 55 | + unit_id: string; |
| 56 | + internal_code: string; |
| 57 | + barcode: string; |
| 58 | + name: string; |
| 59 | + short_description: string; |
| 60 | + description: string; |
| 61 | + weight: number; |
| 62 | + height: number; |
| 63 | + width: number; |
| 64 | + length: number; |
| 65 | + featured: boolean; |
| 66 | +} |
| 67 | + |
| 68 | +/** Campos da aba Geral compartilhados entre create e workspace */ |
| 69 | +export interface ProductGeneralFormData { |
| 70 | + name: string; |
| 71 | + slug: string; |
| 72 | + shortDescription: string; |
| 73 | + description: string; |
| 74 | + categoryId: string; |
| 75 | + manufacturerId: string; |
| 76 | + partOriginId: string; |
| 77 | + statusId: string; |
| 78 | + internalCode: string; |
| 79 | + barcode: string; |
| 80 | + unitId: string; |
| 81 | + weight: number; |
| 82 | + height: number; |
| 83 | + width: number; |
| 84 | + length: number; |
| 85 | + featured: boolean; |
| 86 | + active: boolean; |
| 87 | +} |
| 88 | + |
| 89 | +export interface ProductGeneralFormOptions { |
| 90 | + categoryOptions: AutocompleteOption[]; |
| 91 | + categoryLoading: boolean; |
| 92 | + manufacturerOptions: AutocompleteOption[]; |
| 93 | + manufacturerLoading: boolean; |
| 94 | + partOriginOptions: DSelectOption[]; |
| 95 | + unitOptions: DSelectOption[]; |
| 96 | + statusOptions: DSelectOption[]; |
| 97 | +} |
| 98 | + |
| 99 | +export interface ProductGeneralFormSource { |
| 100 | + name: string; |
| 101 | + slug: string; |
| 102 | + shortDescription: string; |
| 103 | + description: string; |
| 104 | + categoryId: string; |
| 105 | + manufacturerId: string; |
| 106 | + partOriginId: string; |
| 107 | + statusId: string; |
| 108 | + internalCode: string; |
| 109 | + barcode: string; |
| 110 | + unitId: string; |
| 111 | + weight: number; |
| 112 | + height: number; |
| 113 | + width: number; |
| 114 | + length: number; |
| 115 | + featured: boolean; |
| 116 | + active: boolean; |
| 117 | +} |
| 118 | + |
| 119 | +export function toProductGeneralFormData(source: ProductGeneralFormSource): ProductGeneralFormData { |
| 120 | + return { |
| 121 | + name: source.name, |
| 122 | + slug: source.slug, |
| 123 | + shortDescription: source.shortDescription, |
| 124 | + description: source.description, |
| 125 | + categoryId: source.categoryId, |
| 126 | + manufacturerId: source.manufacturerId, |
| 127 | + partOriginId: source.partOriginId, |
| 128 | + statusId: source.statusId, |
| 129 | + internalCode: source.internalCode, |
| 130 | + barcode: source.barcode, |
| 131 | + unitId: source.unitId, |
| 132 | + weight: source.weight, |
| 133 | + height: source.height, |
| 134 | + width: source.width, |
| 135 | + length: source.length, |
| 136 | + featured: source.featured, |
| 137 | + active: source.active, |
| 138 | + }; |
| 139 | +} |
| 140 | + |
| 141 | +export function toCreateProductPayload(source: ProductGeneralFormSource): CreateProductPayload { |
| 142 | + return { |
| 143 | + category_id: source.categoryId, |
| 144 | + manufacturer_id: source.manufacturerId, |
| 145 | + part_origin_id: source.partOriginId, |
| 146 | + unit_id: source.unitId, |
| 147 | + internal_code: source.internalCode, |
| 148 | + barcode: source.barcode, |
| 149 | + name: source.name, |
| 150 | + short_description: source.shortDescription, |
| 151 | + description: source.description, |
| 152 | + weight: source.weight, |
| 153 | + height: source.height, |
| 154 | + width: source.width, |
| 155 | + length: source.length, |
| 156 | + featured: source.featured, |
| 157 | + }; |
| 158 | +} |
0 commit comments