fix build issue

This commit is contained in:
wass08
2026-02-11 15:47:29 +09:00
parent 2e8b663001
commit 77b00f09d6
4 changed files with 67 additions and 63 deletions
@@ -49,7 +49,7 @@ export async function getPropertyModel(propertyId: string): Promise<ActionResult
.from('properties') .from('properties')
.select('id, owner_id') .select('id, owner_id')
.eq('id', propertyId) .eq('id', propertyId)
.single() .single<{ id: string; owner_id: string }>()
if (propertyError || !property) { if (propertyError || !property) {
return { return {
@@ -77,7 +77,7 @@ export async function getPropertyModel(propertyId: string): Promise<ActionResult
.order('version', { ascending: false }) .order('version', { ascending: false })
.order('created_at', { ascending: false }) .order('created_at', { ascending: false })
.limit(1) .limit(1)
.single() .single<PropertyModel>()
console.log('[getPropertyModel] Query result:', { console.log('[getPropertyModel] Query result:', {
propertyId, propertyId,
@@ -149,7 +149,7 @@ export async function savePropertyModel(
.from('properties') .from('properties')
.select('id, owner_id, name') .select('id, owner_id, name')
.eq('id', propertyId) .eq('id', propertyId)
.single() .single<{ id: string; owner_id: string; name: string }>()
if (propertyError || !property) { if (propertyError || !property) {
return { return {
@@ -175,19 +175,20 @@ export async function savePropertyModel(
.order('version', { ascending: false }) .order('version', { ascending: false })
.order('created_at', { ascending: false }) .order('created_at', { ascending: false })
.limit(1) .limit(1)
.single() .single<{ id: string; version: number }>()
if (existingModel) { if (existingModel) {
// Update existing model // Update existing model
const { data: updatedModel, error: updateError } = await supabase const updateData = {
.from('properties_models') scene_graph: sceneGraph,
.update({
scene_graph: sceneGraph as any,
updated_at: new Date().toISOString(), updated_at: new Date().toISOString(),
}) }
const { data: updatedModel, error: updateError } = (await (supabase
.from('properties_models') as any)
.update(updateData)
.eq('id', existingModel.id) .eq('id', existingModel.id)
.select() .select()
.single() .single()) as { data: PropertyModel | null; error: any }
if (updateError) { if (updateError) {
return { return {
@@ -205,18 +206,19 @@ export async function savePropertyModel(
// Create new model // Create new model
const modelId = createId('model') const modelId = createId('model')
const { data: newModel, error: createError } = await supabase const insertData = {
.from('properties_models')
.insert({
id: modelId, id: modelId,
property_id: propertyId, property_id: propertyId,
name: `${property.name} - Editor`, name: `${property.name} - Editor`,
version: 1, version: 1,
draft: true, draft: true,
scene_graph: sceneGraph as any, scene_graph: sceneGraph,
}) }
const { data: newModel, error: createError } = (await (supabase
.from('properties_models') as any)
.insert(insertData)
.select() .select()
.single() .single()) as { data: PropertyModel | null; error: any }
if (createError) { if (createError) {
return { return {
@@ -21,7 +21,7 @@ export function usePropertyScene() {
const isLoadingProperty = usePropertyStore((state) => state.isLoading) const isLoadingProperty = usePropertyStore((state) => state.isLoading)
const lastPropertyIdRef = useRef<string | null>(null) const lastPropertyIdRef = useRef<string | null>(null)
const saveTimeoutRef = useRef<NodeJS.Timeout>() const saveTimeoutRef = useRef<NodeJS.Timeout | undefined>(undefined)
const isSavingRef = useRef(false) const isSavingRef = useRef(false)
const currentPropertyIdRef = useRef<string | null>(null) const currentPropertyIdRef = useRef<string | null>(null)
@@ -86,7 +86,7 @@ export async function getActiveProperty(): Promise<ActionResult<Property | null>
.from('auth_sessions') .from('auth_sessions')
.select('active_property_id') .select('active_property_id')
.eq('user_id', session.user.id) .eq('user_id', session.user.id)
.single() .single<{ active_property_id: string | null }>()
if (sessionError || !sessionData?.active_property_id) { if (sessionError || !sessionData?.active_property_id) {
return { return {
@@ -103,7 +103,7 @@ export async function getActiveProperty(): Promise<ActionResult<Property | null>
address:properties_addresses(*) address:properties_addresses(*)
`) `)
.eq('id', sessionData.active_property_id) .eq('id', sessionData.active_property_id)
.single() .single<Property>()
if (error) { if (error) {
return { return {
@@ -143,8 +143,8 @@ export async function setActiveProperty(propertyId: string | null): Promise<Acti
const supabase = await createServerSupabaseClient() const supabase = await createServerSupabaseClient()
// Update session's active_property_id // Update session's active_property_id
const { error } = await supabase const { error } = await (supabase
.from('auth_sessions') .from('auth_sessions') as any)
.update({ active_property_id: propertyId }) .update({ active_property_id: propertyId })
.eq('user_id', session.user.id) .eq('user_id', session.user.id)
@@ -188,9 +188,7 @@ export async function createProperty(params: CreatePropertyParams): Promise<Acti
const propertyId = createId('property') const propertyId = createId('property')
// First, create the address // First, create the address
const { data: address, error: addressError } = await supabase const addressData = {
.from('properties_addresses')
.insert({
id: addressId, id: addressId,
street_number: params.streetNumber, street_number: params.streetNumber,
route: params.route, route: params.route,
@@ -200,9 +198,12 @@ export async function createProperty(params: CreatePropertyParams): Promise<Acti
country: params.country || 'US', country: params.country || 'US',
latitude: params.center[1].toString(), latitude: params.center[1].toString(),
longitude: params.center[0].toString(), longitude: params.center[0].toString(),
}) }
const { data: address, error: addressError } = (await (supabase
.from('properties_addresses') as any)
.insert(addressData)
.select() .select()
.single() .single()) as { data: Property['address'] | null; error: any }
if (addressError || !address) { if (addressError || !address) {
return { return {
@@ -212,9 +213,7 @@ export async function createProperty(params: CreatePropertyParams): Promise<Acti
} }
// Create the property // Create the property
const { data, error } = await supabase const propertyData = {
.from('properties')
.insert({
id: propertyId, id: propertyId,
name: params.name, name: params.name,
address_id: address.id, address_id: address.id,
@@ -223,12 +222,15 @@ export async function createProperty(params: CreatePropertyParams): Promise<Acti
coordinates: params.center, coordinates: params.center,
createdFrom: 'editor-app', createdFrom: 'editor-app',
}, },
}) }
const { data, error } = (await (supabase
.from('properties') as any)
.insert(propertyData)
.select(` .select(`
*, *,
address:properties_addresses(*) address:properties_addresses(*)
`) `)
.single() .single()) as { data: Property | null; error: any }
if (error) { if (error) {
return { return {
@@ -300,12 +302,12 @@ export async function checkPropertyDuplicate(params: {
} }
if (data && data.length > 0) { if (data && data.length > 0) {
const existingProperty = data[0] as Property const existingProperty = data[0] as unknown as Property
return { return {
success: true, success: true,
data: { data: {
isDuplicate: true, isDuplicate: true,
isUserProperty: existingProperty.ownerId === session.user.id, isUserProperty: existingProperty.owner_id === session.user.id,
existingProperty, existingProperty,
}, },
} }
@@ -6,18 +6,18 @@
export type Property = { export type Property = {
id: string id: string
name: string name: string
ownerId: string owner_id: string
organizationId: string | null organization_id: string | null
addressId: string address_id: string
createdAt: Date created_at: string
updatedAt: Date updated_at: string
address: { address: {
id: string id: string
streetNumber?: string street_number?: string
route?: string route?: string
city?: string city?: string
state?: string state?: string
postalCode?: string postal_code?: string
country?: string country?: string
latitude?: string latitude?: string
longitude?: string longitude?: string