set parent location during location creation

This commit is contained in:
Hayden 2023-01-27 14:25:52 -09:00
parent 6f3f072a04
commit 66ea327595
No known key found for this signature in database
GPG key ID: 17CF79474E257545
3 changed files with 54 additions and 28 deletions

View file

@ -19,8 +19,9 @@ type LocationRepository struct {
type ( type (
LocationCreate struct { LocationCreate struct {
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"`
Description string `json:"description"`
} }
LocationUpdate struct { LocationUpdate struct {
@ -170,11 +171,18 @@ func (r *LocationRepository) GetOneByGroup(ctx context.Context, GID, ID uuid.UUI
} }
func (r *LocationRepository) Create(ctx context.Context, GID uuid.UUID, data LocationCreate) (LocationOut, error) { func (r *LocationRepository) Create(ctx context.Context, GID uuid.UUID, data LocationCreate) (LocationOut, error) {
location, err := r.db.Location.Create(). q := r.db.Location.Create().
SetName(data.Name). SetName(data.Name).
SetDescription(data.Description). SetDescription(data.Description).
SetGroupID(GID). SetGroupID(GID)
Save(ctx)
println(data.ParentID.String())
if data.ParentID != uuid.Nil {
println("SET PARENT")
q.SetParentID(data.ParentID)
}
location, err := q.Save(ctx)
if err != nil { if err != nil {
return LocationOut{}, err return LocationOut{}, err

View file

@ -10,6 +10,13 @@
label="Location Name" label="Location Name"
/> />
<FormTextArea v-model="form.description" label="Location Description" /> <FormTextArea v-model="form.description" label="Location Description" />
<FormAutocomplete
v-model="form.parent"
:items="locations"
item-text="name"
item-value="id"
label="Parent Location"
/>
<div class="modal-action"> <div class="modal-action">
<BaseButton type="submit" :loading="loading"> Create </BaseButton> <BaseButton type="submit" :loading="loading"> Create </BaseButton>
</div> </div>
@ -18,6 +25,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { LocationSummary } from "~~/lib/api/types/data-contracts";
import { useLocationStore } from "~~/stores/locations";
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
type: Boolean, type: Boolean,
@ -25,12 +34,16 @@
}, },
}); });
const locationStore = useLocationStore();
const locations = computed(() => locationStore.allLocations);
const modal = useVModel(props, "modelValue"); const modal = useVModel(props, "modelValue");
const loading = ref(false); const loading = ref(false);
const focused = ref(false); const focused = ref(false);
const form = reactive({ const form = reactive({
name: "", name: "",
description: "", description: "",
parent: null as LocationSummary | null,
}); });
whenever( whenever(
@ -43,6 +56,7 @@
function reset() { function reset() {
form.name = ""; form.name = "";
form.description = ""; form.description = "";
form.parent = null;
focused.value = false; focused.value = false;
modal.value = false; modal.value = false;
loading.value = false; loading.value = false;
@ -54,7 +68,11 @@
async function create() { async function create() {
loading.value = true; loading.value = true;
const { data, error } = await api.locations.create(form); const { data, error } = await api.locations.create({
name: form.name,
description: form.description,
parentId: form.parent ? form.parent.id : null,
});
if (error) { if (error) {
toast.error("Couldn't create location"); toast.error("Couldn't create location");

View file

@ -17,11 +17,11 @@ export interface DocumentOut {
} }
export interface Group { export interface Group {
createdAt: Date; createdAt: string;
currency: string; currency: string;
id: string; id: string;
name: string; name: string;
updatedAt: Date; updatedAt: string;
} }
export interface GroupStatistics { export interface GroupStatistics {
@ -39,11 +39,11 @@ export interface GroupUpdate {
} }
export interface ItemAttachment { export interface ItemAttachment {
createdAt: Date; createdAt: string;
document: DocumentOut; document: DocumentOut;
id: string; id: string;
type: string; type: string;
updatedAt: Date; updatedAt: string;
} }
export interface ItemAttachmentUpdate { export interface ItemAttachmentUpdate {
@ -76,7 +76,7 @@ export interface ItemOut {
assetId: string; assetId: string;
attachments: ItemAttachment[]; attachments: ItemAttachment[];
children: ItemSummary[]; children: ItemSummary[];
createdAt: Date; createdAt: string;
description: string; description: string;
fields: ItemField[]; fields: ItemField[];
id: string; id: string;
@ -103,16 +103,16 @@ export interface ItemOut {
/** @example "0" */ /** @example "0" */
soldPrice: string; soldPrice: string;
/** Sold */ /** Sold */
soldTime: Date; soldTime: string;
soldTo: string; soldTo: string;
updatedAt: Date; updatedAt: string;
warrantyDetails: string; warrantyDetails: string;
warrantyExpires: Date; warrantyExpires: string;
} }
export interface ItemSummary { export interface ItemSummary {
archived: boolean; archived: boolean;
createdAt: Date; createdAt: string;
description: string; description: string;
id: string; id: string;
insured: boolean; insured: boolean;
@ -123,7 +123,7 @@ export interface ItemSummary {
/** @example "0" */ /** @example "0" */
purchasePrice: string; purchasePrice: string;
quantity: number; quantity: number;
updatedAt: Date; updatedAt: string;
} }
export interface ItemUpdate { export interface ItemUpdate {
@ -156,10 +156,10 @@ export interface ItemUpdate {
/** @example "0" */ /** @example "0" */
soldPrice: string; soldPrice: string;
/** Sold */ /** Sold */
soldTime: Date; soldTime: string;
soldTo: string; soldTo: string;
warrantyDetails: string; warrantyDetails: string;
warrantyExpires: Date; warrantyExpires: string;
} }
export interface LabelCreate { export interface LabelCreate {
@ -169,20 +169,20 @@ export interface LabelCreate {
} }
export interface LabelOut { export interface LabelOut {
createdAt: Date; createdAt: string;
description: string; description: string;
id: string; id: string;
items: ItemSummary[]; items: ItemSummary[];
name: string; name: string;
updatedAt: Date; updatedAt: string;
} }
export interface LabelSummary { export interface LabelSummary {
createdAt: Date; createdAt: string;
description: string; description: string;
id: string; id: string;
name: string; name: string;
updatedAt: Date; updatedAt: string;
} }
export interface LocationCreate { export interface LocationCreate {
@ -193,30 +193,30 @@ export interface LocationCreate {
export interface LocationOut { export interface LocationOut {
children: LocationSummary[]; children: LocationSummary[];
createdAt: Date; createdAt: string;
description: string; description: string;
id: string; id: string;
items: ItemSummary[]; items: ItemSummary[];
name: string; name: string;
parent: LocationSummary; parent: LocationSummary;
updatedAt: Date; updatedAt: string;
} }
export interface LocationOutCount { export interface LocationOutCount {
createdAt: Date; createdAt: string;
description: string; description: string;
id: string; id: string;
itemCount: number; itemCount: number;
name: string; name: string;
updatedAt: Date; updatedAt: string;
} }
export interface LocationSummary { export interface LocationSummary {
createdAt: Date; createdAt: string;
description: string; description: string;
id: string; id: string;
name: string; name: string;
updatedAt: Date; updatedAt: string;
} }
export interface LocationUpdate { export interface LocationUpdate {