u
This commit is contained in:
@@ -95,7 +95,7 @@ const MENU = {
|
||||
category: {
|
||||
label: 'category',
|
||||
items: [
|
||||
{ value: 'category.create', label: 'create', hint: '{parent_id, sort} → id' },
|
||||
{ value: 'category.create', label: 'create', hint: '{parentId, sort} → id' },
|
||||
{ value: 'category.updateParentId', label: 'updateParentId', hint: 'id, parentId' },
|
||||
{ value: 'category.delete', label: 'delete', hint: 'id' },
|
||||
{ value: 'category.getTree', label: 'getTree', hint: 'rootId → rows' },
|
||||
@@ -112,12 +112,11 @@ const MENU = {
|
||||
google_auth: {
|
||||
label: 'google_auth',
|
||||
items: [
|
||||
{ value: 'google_auth.add', label: 'add', hint: 'email → authId' },
|
||||
{ value: 'google_auth.getById', label: 'getById', hint: 'id → row' },
|
||||
{ value: 'google_auth.add', label: 'add', hint: 'email → id' },
|
||||
{ value: 'google_auth.getByEmail', label: 'getByEmail', hint: 'email → row' },
|
||||
{ value: 'google_auth.listAllowedEmails', label: 'listAllowedEmails', hint: '→ rows' },
|
||||
{ value: 'google_auth.removeAllowedEmail', label: 'removeAllowedEmail', hint: 'email' },
|
||||
{ value: 'google_auth.setSelectedCompany', label: 'setSelectedCompany', hint: 'authId, companyId' },
|
||||
{ value: 'google_auth.list', label: 'list', hint: '→ rows' },
|
||||
{ value: 'google_auth.del', label: 'del', hint: 'id' },
|
||||
],
|
||||
},
|
||||
schema: {
|
||||
@@ -186,13 +185,10 @@ async function runMethod(client, action) {
|
||||
reducedtaxrate,
|
||||
});
|
||||
const companyId = created.id;
|
||||
|
||||
const auths = await client.google_auth.list();
|
||||
const existingAuth = auths.find((row) => row.email === email);
|
||||
const authId = existingAuth
|
||||
? existingAuth.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);
|
||||
|
||||
@@ -207,7 +203,6 @@ async function runMethod(client, action) {
|
||||
iso639,
|
||||
taxrate,
|
||||
reducedtaxrate,
|
||||
authCreated: !existingAuth,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -298,7 +293,7 @@ async function runMethod(client, action) {
|
||||
return ['ok', true];
|
||||
}
|
||||
case 'category.create': {
|
||||
const parentRaw = await askText('parent_id (null as empty)', {
|
||||
const parentRaw = await askText('parentId (null as empty)', {
|
||||
placeholder: '',
|
||||
validate: (v) =>
|
||||
v?.trim() && !/^\d+$/.test(v.trim()) ? 'Integer or empty' : undefined,
|
||||
@@ -306,13 +301,13 @@ async function runMethod(client, action) {
|
||||
if (parentRaw == null) return;
|
||||
const sortRaw = await askInt('sort', '0');
|
||||
if (sortRaw == null) return;
|
||||
const parent_id = parentRaw === '' ? null : Number(parentRaw);
|
||||
return ['id', await client.category.create({ parent_id, sort: Number(sortRaw) })];
|
||||
const parentId = parentRaw === '' ? null : Number(parentRaw);
|
||||
return ['id', await client.category.create({ parentId, sort: Number(sortRaw) })];
|
||||
}
|
||||
case 'category.updateParentId': {
|
||||
const id = await askInt('Category id');
|
||||
if (id == null) return;
|
||||
const parentRaw = await askText('parent_id (null as empty)', {
|
||||
const parentRaw = await askText('parentId (null as empty)', {
|
||||
placeholder: '',
|
||||
validate: (v) =>
|
||||
v?.trim() && !/^\d+$/.test(v.trim()) ? 'Integer or empty' : undefined,
|
||||
@@ -360,12 +355,7 @@ async function runMethod(client, action) {
|
||||
validate: (v) => (!v?.trim() ? 'Required' : undefined),
|
||||
});
|
||||
if (email == null) return;
|
||||
return ['authId', await client.google_auth.add(email)];
|
||||
}
|
||||
case 'google_auth.getById': {
|
||||
const id = await askInt('Auth id');
|
||||
if (id == null) return;
|
||||
return ['row', await client.google_auth.getById(Number(id))];
|
||||
return ['id', await client.google_auth.add(email)];
|
||||
}
|
||||
case 'google_auth.getByEmail': {
|
||||
const email = await askText('Email', {
|
||||
@@ -375,6 +365,18 @@ async function runMethod(client, action) {
|
||||
if (email == null) return;
|
||||
return ['row', await client.google_auth.getByEmail(email)];
|
||||
}
|
||||
case 'google_auth.listAllowedEmails': {
|
||||
return ['rows', await client.google_auth.listAllowedEmails()];
|
||||
}
|
||||
case 'google_auth.removeAllowedEmail': {
|
||||
const email = await askText('Email', {
|
||||
placeholder: 'user@example.com',
|
||||
validate: (v) => (!v?.trim() ? 'Required' : undefined),
|
||||
});
|
||||
if (email == null) return;
|
||||
await client.google_auth.removeAllowedEmail(email);
|
||||
return ['ok', true];
|
||||
}
|
||||
case 'google_auth.setSelectedCompany': {
|
||||
const id = await askInt('Auth id');
|
||||
if (id == null) return;
|
||||
@@ -383,15 +385,6 @@ async function runMethod(client, action) {
|
||||
await client.google_auth.setSelectedCompany(Number(id), Number(companyId));
|
||||
return ['ok', true];
|
||||
}
|
||||
case 'google_auth.list': {
|
||||
return ['rows', await client.google_auth.list()];
|
||||
}
|
||||
case 'google_auth.del': {
|
||||
const id = await askInt('Auth id');
|
||||
if (id == null) return;
|
||||
await client.google_auth.del(Number(id));
|
||||
return ['ok', true];
|
||||
}
|
||||
case 'initialize': {
|
||||
await client.initialize();
|
||||
return ['ok', true];
|
||||
|
||||
Reference in New Issue
Block a user