This commit is contained in:
seb
2026-07-31 07:22:34 +02:00
parent 02bca8e236
commit bbd69e8c7c
29 changed files with 144 additions and 87 deletions

21
scripts/purge-db.js Normal file
View File

@@ -0,0 +1,21 @@
import 'dotenv/config';
import sql from 'mssql';
import { buildPurgeSql } from '../src/sql/purge.js';
const pool = await sql.connect({
server: process.env.MSSQL_SERVER,
database: process.env.MSSQL_DATABASE,
user: process.env.MSSQL_USER,
password: process.env.MSSQL_PASSWORD,
options: {
encrypt: false,
trustServerCertificate: true,
},
});
try {
await pool.request().query(buildPurgeSql());
console.log('Database purged');
} finally {
await pool.close();
}

25
scripts/reset-db.js Normal file
View File

@@ -0,0 +1,25 @@
import 'dotenv/config';
import sql from 'mssql';
import { buildPurgeSql } from '../src/sql/purge.js';
import { SCHEMA_SCRIPTS } from '../src/schema.js';
const pool = await sql.connect({
server: process.env.MSSQL_SERVER,
database: process.env.MSSQL_DATABASE,
user: process.env.MSSQL_USER,
password: process.env.MSSQL_PASSWORD,
options: {
encrypt: false,
trustServerCertificate: true,
},
});
try {
await pool.request().query(buildPurgeSql());
for (const script of SCHEMA_SCRIPTS) {
await pool.request().query(script);
}
console.log(`Database reset (${SCHEMA_SCRIPTS.length} schema scripts applied)`);
} finally {
await pool.close();
}

View File

@@ -70,9 +70,9 @@ const MENU = {
company: {
label: 'company',
items: [
{ value: 'company.create', label: 'create', hint: 'iso639,name,taxes → result' },
{ value: 'company.create', label: 'create', hint: 'authId, iso639, name, taxes → result' },
{ value: 'company.update', label: 'update', hint: 'id + fields → result' },
{ value: 'company.list', label: 'list', hint: '→ result[]' },
{ value: 'company.list', label: 'list', hint: 'authId → result[]' },
{ value: 'company.delete', label: 'delete', hint: 'companyId' },
],
},
@@ -178,25 +178,25 @@ async function runMethod(client, action) {
const reducedtaxrate = await askNumber('Reduced tax rate', '7');
if (reducedtaxrate == null) return;
const existing = await client.google_auth.getByEmail(email);
const authId = existing
? existing.id
: await client.google_auth.add(email);
const created = await client.company.create({
iso639,
name,
taxrate,
reducedtaxrate,
authId,
});
const companyId = created.id;
const existing = await client.google_auth.getByEmail(email);
const authId = existing
? existing.id
: await client.google_auth.add(email);
const companyUserId = await client.companyuser.add(companyId, authId);
await client.google_auth.setSelectedCompany(authId, companyId);
return [
'created',
{
...created,
companyUserId,
authId,
email,
name,
@@ -207,6 +207,8 @@ async function runMethod(client, action) {
];
}
case 'company.create': {
const authId = await askInt('google_auth id');
if (authId == null) return;
const name = await askText('Name', {
placeholder: 'Acme',
validate: (v) => (!v?.trim() ? 'Required' : undefined),
@@ -223,7 +225,13 @@ async function runMethod(client, action) {
if (reducedtaxrate == null) return;
return [
'result',
await client.company.create({ iso639, name, taxrate, reducedtaxrate }),
await client.company.create({
iso639,
name,
taxrate,
reducedtaxrate,
authId: Number(authId),
}),
];
}
case 'company.update': {
@@ -254,7 +262,9 @@ async function runMethod(client, action) {
];
}
case 'company.list': {
return ['result[]', await client.company.list()];
const authId = await askInt('google_auth id');
if (authId == null) return;
return ['result[]', await client.company.list(Number(authId))];
}
case 'company.delete': {
const companyId = await askInt('Company id');