Seed route-ready team addresses
Build and deploy Docker image / build (push) Successful in 2m42s

This commit is contained in:
Ruslan Bakiev
2026-08-24 14:20:22 +07:00
parent ccdf536763
commit 6e6badc419
2 changed files with 75 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
import { createHash } from 'node:crypto'
import { prisma } from './db.js'
interface DemoAddress {
name: string
address: string
latitude: number
longitude: number
countryCode: string
}
const demoAddresses: DemoAddress[] = [
{
name: 'Almaty warehouse',
address: 'Tole Bi Street 101, Almaty',
latitude: 43.2527,
longitude: 76.9278,
countryCode: 'KZ',
},
{
name: 'Moscow office',
address: 'Presnenskaya Embankment 8, Moscow',
latitude: 55.7472,
longitude: 37.5391,
countryCode: 'RU',
},
{
name: 'Dubai warehouse',
address: 'Dubai South Logistics District, Dubai',
latitude: 24.8964,
longitude: 55.1614,
countryCode: 'AE',
},
]
function stableUuid(teamUuid: string, index: number): string {
const hex = createHash('sha256')
.update(`${teamUuid}:demo-address:${index}`)
.digest('hex')
.slice(0, 32)
.split('')
hex[12] = '4'
hex[16] = '8'
const value = hex.join('')
return `${value.slice(0, 8)}-${value.slice(8, 12)}-${value.slice(12, 16)}-${value.slice(16, 20)}-${value.slice(20)}`
}
export async function ensureDemoTeamAddresses(teamId: number, teamUuid: string): Promise<void> {
const addressCount = await prisma.teamAddress.count({ where: { teamId } })
if (addressCount > 0) return
for (const [index, address] of demoAddresses.entries()) {
await prisma.teamAddress.upsert({
where: { uuid: stableUuid(teamUuid, index) },
create: {
uuid: stableUuid(teamUuid, index),
teamId,
...address,
isDefault: index === 0,
status: 'ready',
processedAt: new Date(),
},
update: {
teamId,
...address,
isDefault: index === 0,
status: 'ready',
},
})
}
}