Scaffold Apollo backend domain API

This commit is contained in:
Ruslan Bakiev
2026-03-30 21:41:06 +07:00
parent 498b800bc4
commit 6a6c6bfdbb
16 changed files with 4539 additions and 1 deletions

34
scripts/load-vault-env.sh Executable file
View File

@@ -0,0 +1,34 @@
#!/bin/sh
set -eu
if [ "${VAULT_ENABLED:-auto}" = "false" ] || [ "${VAULT_ENABLED:-auto}" = "0" ]; then
exit 0
fi
if [ -z "${VAULT_ADDR:-}" ] || [ -z "${VAULT_TOKEN:-}" ]; then
if [ "${VAULT_ENABLED:-auto}" = "true" ] || [ "${VAULT_ENABLED:-auto}" = "1" ]; then
echo "VAULT_ENABLED=true but VAULT_ADDR/VAULT_TOKEN are not set" >&2
exit 1
fi
exit 0
fi
if ! command -v curl >/dev/null 2>&1 || ! command -v jq >/dev/null 2>&1; then
echo "Vault bootstrap requires curl and jq." >&2
exit 1
fi
kv_mount="${VAULT_KV_MOUNT:-secret}"
load_path() {
path="$1"
[ -z "$path" ] && return 0
payload="$(curl -fsS -H "X-Vault-Token: ${VAULT_TOKEN}" "${VAULT_ADDR%/}/v1/${kv_mount}/data/${path}")"
echo "$payload" | jq -r '.data.data // {} | to_entries[] | "\(.key)=\(.value|tostring)"' | while IFS='=' read -r k v; do
export "$k=$v"
done
}
load_path "${VAULT_SHARED_PATH:-}"
load_path "${VAULT_PROJECT_PATH:-}"

119
scripts/seed.js Normal file
View File

@@ -0,0 +1,119 @@
import 'dotenv/config';
import { prisma } from '../src/prisma-client.js';
const managerEmail = 'manager@fregat.local';
const clientEmail = 'client@fregat.local';
const company = await prisma.company.upsert({
where: { inn: '7701000000' },
update: {},
create: {
name: 'Fregat Client LLC',
inn: '7701000000',
},
});
const manager = await prisma.user.upsert({
where: { email: managerEmail },
update: { fullName: 'Default Manager' },
create: {
email: managerEmail,
fullName: 'Default Manager',
role: 'MANAGER',
},
});
await prisma.user.upsert({
where: { email: clientEmail },
update: { fullName: 'Demo Client', companyId: company.id },
create: {
email: clientEmail,
fullName: 'Demo Client',
role: 'CLIENT',
companyId: company.id,
},
});
const warehouseMain = await prisma.warehouse.upsert({
where: { code: 'MSK-01' },
update: { name: 'Main warehouse' },
create: { code: 'MSK-01', name: 'Main warehouse' },
});
const warehouseReserve = await prisma.warehouse.upsert({
where: { code: 'SPB-01' },
update: { name: 'Reserve warehouse' },
create: { code: 'SPB-01', name: 'Reserve warehouse' },
});
const products = [
{
sku: 'FILM-100',
name: 'Пленка прозрачная 100мкм',
description: 'Готовая продукция для стандартной упаковки',
isCustomizable: false,
qtyMain: 1250,
qtyReserve: 420,
},
{
sku: 'FILM-200-COLOR',
name: 'Пленка цветная 200мкм',
description: 'Продукция с дополнительной окраской',
isCustomizable: true,
qtyMain: 860,
qtyReserve: 230,
},
];
for (const product of products) {
const dbProduct = await prisma.product.upsert({
where: { sku: product.sku },
update: {
name: product.name,
description: product.description,
isCustomizable: product.isCustomizable,
isActive: true,
},
create: {
sku: product.sku,
name: product.name,
description: product.description,
isCustomizable: product.isCustomizable,
isActive: true,
},
});
await prisma.productStock.upsert({
where: {
productId_warehouseId: {
productId: dbProduct.id,
warehouseId: warehouseMain.id,
},
},
update: { availableQty: product.qtyMain },
create: {
productId: dbProduct.id,
warehouseId: warehouseMain.id,
availableQty: product.qtyMain,
},
});
await prisma.productStock.upsert({
where: {
productId_warehouseId: {
productId: dbProduct.id,
warehouseId: warehouseReserve.id,
},
},
update: { availableQty: product.qtyReserve },
create: {
productId: dbProduct.id,
warehouseId: warehouseReserve.id,
availableQty: product.qtyReserve,
},
});
}
console.log('Seed complete. Use manager header x-user-id:', manager.id);
await prisma.$disconnect();