first commit

This commit is contained in:
2025-04-22 10:56:56 +07:00
commit af123c091b
147 changed files with 778063 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const cities = await prisma.addressCities.findMany({
where: {
Parent: parent.Code,
},
})
return cities.map((c) => {
return {
Code: c.Code,
Name: c.Name,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch cities' },
}
}
})
+31
View File
@@ -0,0 +1,31 @@
import { useToNumber, useToString } from '@vueuse/core'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const limit = useToNumber(useToString(query.limit).value).value || 5
const search = useToString(query.search)
try {
const countries = await prisma.addressCountries.findMany({
// where: {
// Name: {
// startsWith: search.value,
// mode: 'insensitive',
// },
// },
// take: limit,
})
return countries.map((c) => {
return {
Code: c.Code,
Name: c.Name,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch countries' },
}
}
})
+24
View File
@@ -0,0 +1,24 @@
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const districts = await prisma.addressDistricts.findMany({
where: {
Parent: parent.Code,
},
})
return districts.map((c) => {
return {
Code: c.Code,
Name: c.Name,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch districts' },
}
}
})
+181
View File
@@ -0,0 +1,181 @@
import { useFuse } from '@vueuse/integrations/useFuse'
import { useToString } from '@vueuse/core'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const keywords = useToString(query.search).value.split(' ')
const nameSearch = keywords.map((word) => {
return { Name: { startsWith: word, mode: 'insensitive' } }
})
try {
const villages = await prisma.addressVillages.findMany({
where: {
OR: nameSearch,
},
select: {
Name: true,
Postal: true,
District: {
select: {
Name: true,
City: {
select: {
Name: true,
State: {
select: {
Name: true,
Country: {
select: {
Name: true,
},
},
},
},
},
},
},
},
},
take: 100,
})
const districts = await prisma.addressDistricts.findMany({
where: {
OR: nameSearch,
},
select: {
Name: true,
Postal: true,
City: {
select: {
Name: true,
State: {
select: {
Name: true,
Country: {
select: {
Name: true,
},
},
},
},
},
},
},
take: 50,
})
const cities = await prisma.addressCities.findMany({
where: {
OR: nameSearch,
},
select: {
Name: true,
Postal: true,
State: {
select: {
Name: true,
Country: {
select: {
Name: true,
},
},
},
},
},
take: 30,
})
const states = await prisma.addressStates.findMany({
where: {
OR: nameSearch,
},
select: {
Name: true,
Postal: true,
Country: {
select: {
Name: true,
},
},
},
take: 20,
})
const countries = await prisma.addressCountries.findMany({
where: {
OR: nameSearch,
},
select: {
Name: true,
Postal: true,
},
take: 10,
})
const addresses = [
...villages.map((item) => {
return {
villages: item.Name,
districts: item.District?.Name,
cities: item.District?.City?.Name,
states: item.District?.City?.State?.Name,
countries: item.District?.City?.State?.Country?.Name,
postal: item.Postal,
}
}),
...districts.map((item) => {
return {
districts: item.Name,
cities: item.City?.Name,
states: item.City?.State?.Name,
countries: item.City?.State?.Country?.Name,
postal: item.Postal,
}
}),
...cities.map((item) => {
return {
cities: item.Name,
states: item.State?.Name,
countries: item.State?.Country?.Name,
postal: item.Postal,
}
}),
...states.map((item) => {
return {
states: item.Name,
countries: item.Country?.Name,
postal: item.Postal,
}
}),
...countries.map((item) => {
return {
countries: item.Name,
postal: item.Postal,
}
}),
]
const options = {
fuseOptions: {
keys: ['villages', 'districts', 'cities', 'states', 'countries'],
shouldSort: true,
// includeScore: true,
minMatchCharLength: 3,
threshold: 0.8,
},
}
const { results } = useFuse(useToString(query.search), addresses, options)
return results.value
.map((value) => {
return value.item
})
.slice(0, 9)
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch addresses' },
}
}
})
+19
View File
@@ -0,0 +1,19 @@
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const districts = await prisma.addressDistricts.findUnique({
where: {
Code: parent.Code,
},
})
return districts.Postal
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch districts' },
}
}
})
+24
View File
@@ -0,0 +1,24 @@
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const states = await prisma.addressStates.findMany({
where: {
Parent: parent.Code,
},
})
return states.map((c) => {
return {
Code: c.Code,
Name: c.Name,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch states' },
}
}
})
+24
View File
@@ -0,0 +1,24 @@
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const parent = JSON.parse(query.parent)
try {
const villages = await prisma.addressVillages.findMany({
where: {
Parent: parent.Code,
},
})
return villages.map((c) => {
return {
Code: '' + c.Code,
Name: c.Name,
}
})
} catch (error) {
// Return error if fetching users fails
return {
status: 500,
body: { message: 'Failed to fetch villages' },
}
}
})