mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-04 00:30:27 +00:00
set parent location during location creation
This commit is contained in:
parent
6f3f072a04
commit
66ea327595
3 changed files with 54 additions and 28 deletions
|
@ -20,6 +20,7 @@ type LocationRepository struct {
|
|||
type (
|
||||
LocationCreate struct {
|
||||
Name string `json:"name"`
|
||||
ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
location, err := r.db.Location.Create().
|
||||
q := r.db.Location.Create().
|
||||
SetName(data.Name).
|
||||
SetDescription(data.Description).
|
||||
SetGroupID(GID).
|
||||
Save(ctx)
|
||||
SetGroupID(GID)
|
||||
|
||||
println(data.ParentID.String())
|
||||
if data.ParentID != uuid.Nil {
|
||||
println("SET PARENT")
|
||||
q.SetParentID(data.ParentID)
|
||||
}
|
||||
|
||||
location, err := q.Save(ctx)
|
||||
|
||||
if err != nil {
|
||||
return LocationOut{}, err
|
||||
|
|
|
@ -10,6 +10,13 @@
|
|||
label="Location Name"
|
||||
/>
|
||||
<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">
|
||||
<BaseButton type="submit" :loading="loading"> Create </BaseButton>
|
||||
</div>
|
||||
|
@ -18,6 +25,8 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { LocationSummary } from "~~/lib/api/types/data-contracts";
|
||||
import { useLocationStore } from "~~/stores/locations";
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: Boolean,
|
||||
|
@ -25,12 +34,16 @@
|
|||
},
|
||||
});
|
||||
|
||||
const locationStore = useLocationStore();
|
||||
|
||||
const locations = computed(() => locationStore.allLocations);
|
||||
const modal = useVModel(props, "modelValue");
|
||||
const loading = ref(false);
|
||||
const focused = ref(false);
|
||||
const form = reactive({
|
||||
name: "",
|
||||
description: "",
|
||||
parent: null as LocationSummary | null,
|
||||
});
|
||||
|
||||
whenever(
|
||||
|
@ -43,6 +56,7 @@
|
|||
function reset() {
|
||||
form.name = "";
|
||||
form.description = "";
|
||||
form.parent = null;
|
||||
focused.value = false;
|
||||
modal.value = false;
|
||||
loading.value = false;
|
||||
|
@ -54,7 +68,11 @@
|
|||
async function create() {
|
||||
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) {
|
||||
toast.error("Couldn't create location");
|
||||
|
|
|
@ -17,11 +17,11 @@ export interface DocumentOut {
|
|||
}
|
||||
|
||||
export interface Group {
|
||||
createdAt: Date;
|
||||
createdAt: string;
|
||||
currency: string;
|
||||
id: string;
|
||||
name: string;
|
||||
updatedAt: Date;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface GroupStatistics {
|
||||
|
@ -39,11 +39,11 @@ export interface GroupUpdate {
|
|||
}
|
||||
|
||||
export interface ItemAttachment {
|
||||
createdAt: Date;
|
||||
createdAt: string;
|
||||
document: DocumentOut;
|
||||
id: string;
|
||||
type: string;
|
||||
updatedAt: Date;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ItemAttachmentUpdate {
|
||||
|
@ -76,7 +76,7 @@ export interface ItemOut {
|
|||
assetId: string;
|
||||
attachments: ItemAttachment[];
|
||||
children: ItemSummary[];
|
||||
createdAt: Date;
|
||||
createdAt: string;
|
||||
description: string;
|
||||
fields: ItemField[];
|
||||
id: string;
|
||||
|
@ -103,16 +103,16 @@ export interface ItemOut {
|
|||
/** @example "0" */
|
||||
soldPrice: string;
|
||||
/** Sold */
|
||||
soldTime: Date;
|
||||
soldTime: string;
|
||||
soldTo: string;
|
||||
updatedAt: Date;
|
||||
updatedAt: string;
|
||||
warrantyDetails: string;
|
||||
warrantyExpires: Date;
|
||||
warrantyExpires: string;
|
||||
}
|
||||
|
||||
export interface ItemSummary {
|
||||
archived: boolean;
|
||||
createdAt: Date;
|
||||
createdAt: string;
|
||||
description: string;
|
||||
id: string;
|
||||
insured: boolean;
|
||||
|
@ -123,7 +123,7 @@ export interface ItemSummary {
|
|||
/** @example "0" */
|
||||
purchasePrice: string;
|
||||
quantity: number;
|
||||
updatedAt: Date;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ItemUpdate {
|
||||
|
@ -156,10 +156,10 @@ export interface ItemUpdate {
|
|||
/** @example "0" */
|
||||
soldPrice: string;
|
||||
/** Sold */
|
||||
soldTime: Date;
|
||||
soldTime: string;
|
||||
soldTo: string;
|
||||
warrantyDetails: string;
|
||||
warrantyExpires: Date;
|
||||
warrantyExpires: string;
|
||||
}
|
||||
|
||||
export interface LabelCreate {
|
||||
|
@ -169,20 +169,20 @@ export interface LabelCreate {
|
|||
}
|
||||
|
||||
export interface LabelOut {
|
||||
createdAt: Date;
|
||||
createdAt: string;
|
||||
description: string;
|
||||
id: string;
|
||||
items: ItemSummary[];
|
||||
name: string;
|
||||
updatedAt: Date;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface LabelSummary {
|
||||
createdAt: Date;
|
||||
createdAt: string;
|
||||
description: string;
|
||||
id: string;
|
||||
name: string;
|
||||
updatedAt: Date;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface LocationCreate {
|
||||
|
@ -193,30 +193,30 @@ export interface LocationCreate {
|
|||
|
||||
export interface LocationOut {
|
||||
children: LocationSummary[];
|
||||
createdAt: Date;
|
||||
createdAt: string;
|
||||
description: string;
|
||||
id: string;
|
||||
items: ItemSummary[];
|
||||
name: string;
|
||||
parent: LocationSummary;
|
||||
updatedAt: Date;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface LocationOutCount {
|
||||
createdAt: Date;
|
||||
createdAt: string;
|
||||
description: string;
|
||||
id: string;
|
||||
itemCount: number;
|
||||
name: string;
|
||||
updatedAt: Date;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface LocationSummary {
|
||||
createdAt: Date;
|
||||
createdAt: string;
|
||||
description: string;
|
||||
id: string;
|
||||
name: string;
|
||||
updatedAt: Date;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface LocationUpdate {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue