Add entity address/contact tables and CRUD for entity resources
This commit is contained in:
@@ -158,6 +158,43 @@ const MENU = {
|
||||
},
|
||||
],
|
||||
},
|
||||
customergroup: {
|
||||
label: 'customergroup',
|
||||
items: [
|
||||
{ value: 'customergroup.list', label: 'list', hint: 'googleAuthId, companyId → rows' },
|
||||
{ value: 'customergroup.create', label: 'create', hint: 'googleAuthId, companyId, name → row' },
|
||||
{ value: 'customergroup.update', label: 'update', hint: 'googleAuthId, companyId, id, name → row' },
|
||||
{ value: 'customergroup.delete', label: 'delete', hint: 'googleAuthId, companyId, id' },
|
||||
],
|
||||
},
|
||||
entity: {
|
||||
label: 'entity',
|
||||
items: [
|
||||
{ value: 'entity.list', label: 'list', hint: 'googleAuthId, companyId, customergroupId? → rows' },
|
||||
{ value: 'entity.getById', label: 'getById', hint: 'googleAuthId, companyId, id → row' },
|
||||
{ value: 'entity.create', label: 'create', hint: 'googleAuthId, companyId, JSON → row' },
|
||||
{ value: 'entity.update', label: 'update', hint: 'googleAuthId, companyId, id, JSON → row' },
|
||||
{ value: 'entity.delete', label: 'delete', hint: 'googleAuthId, companyId, id' },
|
||||
],
|
||||
},
|
||||
entityaddress: {
|
||||
label: 'entityaddress',
|
||||
items: [
|
||||
{ value: 'entityaddress.list', label: 'list', hint: 'googleAuthId, companyId, entityId → rows' },
|
||||
{ value: 'entityaddress.create', label: 'create', hint: 'googleAuthId, companyId, entityId, JSON → row' },
|
||||
{ value: 'entityaddress.update', label: 'update', hint: 'googleAuthId, companyId, entityId, id, JSON → row' },
|
||||
{ value: 'entityaddress.delete', label: 'delete', hint: 'googleAuthId, companyId, entityId, id' },
|
||||
],
|
||||
},
|
||||
entitycontact: {
|
||||
label: 'entitycontact',
|
||||
items: [
|
||||
{ value: 'entitycontact.list', label: 'list', hint: 'googleAuthId, companyId, entityId → rows' },
|
||||
{ value: 'entitycontact.create', label: 'create', hint: 'googleAuthId, companyId, entityId, JSON → row' },
|
||||
{ value: 'entitycontact.update', label: 'update', hint: 'googleAuthId, companyId, entityId, id, JSON → row' },
|
||||
{ value: 'entitycontact.delete', label: 'delete', hint: 'googleAuthId, companyId, entityId, id' },
|
||||
],
|
||||
},
|
||||
supplier: {
|
||||
label: 'supplier',
|
||||
items: [
|
||||
@@ -681,6 +718,362 @@ async function runMethod(client, action) {
|
||||
await client.brand.delete(Number(googleAuthId), Number(companyId), id);
|
||||
return ['ok', true];
|
||||
}
|
||||
case 'customergroup.list': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
return [
|
||||
'result[]',
|
||||
await client.customergroup.list(Number(googleAuthId), Number(companyId)),
|
||||
];
|
||||
}
|
||||
case 'customergroup.create': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const name = await askText('name', {
|
||||
validate: (v) => (!v?.trim() ? 'Required' : undefined),
|
||||
});
|
||||
if (name == null) return;
|
||||
return [
|
||||
'result',
|
||||
await client.customergroup.create(Number(googleAuthId), Number(companyId), {
|
||||
name,
|
||||
}),
|
||||
];
|
||||
}
|
||||
case 'customergroup.update': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const id = await askInt('customergroup id');
|
||||
if (id == null) return;
|
||||
const name = await askText('name', {
|
||||
validate: (v) => (!v?.trim() ? 'Required' : undefined),
|
||||
});
|
||||
if (name == null) return;
|
||||
return [
|
||||
'result',
|
||||
await client.customergroup.update(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(id),
|
||||
{ name },
|
||||
),
|
||||
];
|
||||
}
|
||||
case 'customergroup.delete': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const id = await askInt('customergroup id');
|
||||
if (id == null) return;
|
||||
await client.customergroup.delete(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(id),
|
||||
);
|
||||
return ['ok', true];
|
||||
}
|
||||
case 'entity.list': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const groupRaw = await askText('customergroup id (empty = all)', {
|
||||
placeholder: '',
|
||||
validate: (v) =>
|
||||
v?.trim() && !/^\d+$/.test(v.trim()) ? 'Integer or empty' : undefined,
|
||||
});
|
||||
if (groupRaw == null) return;
|
||||
const customergroupId = groupRaw.trim()
|
||||
? Number(groupRaw.trim())
|
||||
: undefined;
|
||||
return [
|
||||
'result[]',
|
||||
await client.entity.list(Number(googleAuthId), Number(companyId), {
|
||||
customergroupId,
|
||||
}),
|
||||
];
|
||||
}
|
||||
case 'entity.getById': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const id = await askInt('entity id');
|
||||
if (id == null) return;
|
||||
return [
|
||||
'result',
|
||||
await client.entity.getById(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(id),
|
||||
),
|
||||
];
|
||||
}
|
||||
case 'entity.create': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const bodyJson = await askText('entity JSON', {
|
||||
placeholder: '{"customergroupId":1,"name":"Acme","firstName":null}',
|
||||
validate: (v) => {
|
||||
if (!v?.trim()) return 'Required';
|
||||
try {
|
||||
JSON.parse(v);
|
||||
} catch {
|
||||
return 'Invalid JSON';
|
||||
}
|
||||
},
|
||||
});
|
||||
if (bodyJson == null) return;
|
||||
return [
|
||||
'result',
|
||||
await client.entity.create(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
JSON.parse(bodyJson),
|
||||
),
|
||||
];
|
||||
}
|
||||
case 'entity.update': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const id = await askInt('entity id');
|
||||
if (id == null) return;
|
||||
const patchJson = await askText('patch JSON', {
|
||||
placeholder: '{"name":"Acme","firstName":"Ada"}',
|
||||
validate: (v) => {
|
||||
if (!v?.trim()) return 'Required';
|
||||
try {
|
||||
JSON.parse(v);
|
||||
} catch {
|
||||
return 'Invalid JSON';
|
||||
}
|
||||
},
|
||||
});
|
||||
if (patchJson == null) return;
|
||||
return [
|
||||
'result',
|
||||
await client.entity.update(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(id),
|
||||
JSON.parse(patchJson),
|
||||
),
|
||||
];
|
||||
}
|
||||
case 'entity.delete': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const id = await askInt('entity id');
|
||||
if (id == null) return;
|
||||
await client.entity.delete(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(id),
|
||||
);
|
||||
return ['ok', true];
|
||||
}
|
||||
case 'entityaddress.list': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const entityId = await askInt('entity id');
|
||||
if (entityId == null) return;
|
||||
return [
|
||||
'result[]',
|
||||
await client.entityaddress.list(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(entityId),
|
||||
),
|
||||
];
|
||||
}
|
||||
case 'entityaddress.create': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const entityId = await askInt('entity id');
|
||||
if (entityId == null) return;
|
||||
const bodyJson = await askText('address JSON', {
|
||||
placeholder:
|
||||
'{"addressType":"billing","street":"Main","streetNumber":"1","zip":"1010","city":"Wien"}',
|
||||
validate: (v) => {
|
||||
if (!v?.trim()) return 'Required';
|
||||
try {
|
||||
JSON.parse(v);
|
||||
} catch {
|
||||
return 'Invalid JSON';
|
||||
}
|
||||
},
|
||||
});
|
||||
if (bodyJson == null) return;
|
||||
return [
|
||||
'result',
|
||||
await client.entityaddress.create(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(entityId),
|
||||
JSON.parse(bodyJson),
|
||||
),
|
||||
];
|
||||
}
|
||||
case 'entityaddress.update': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const entityId = await askInt('entity id');
|
||||
if (entityId == null) return;
|
||||
const id = await askInt('address id');
|
||||
if (id == null) return;
|
||||
const patchJson = await askText('patch JSON', {
|
||||
placeholder: '{"city":"Graz"}',
|
||||
validate: (v) => {
|
||||
if (!v?.trim()) return 'Required';
|
||||
try {
|
||||
JSON.parse(v);
|
||||
} catch {
|
||||
return 'Invalid JSON';
|
||||
}
|
||||
},
|
||||
});
|
||||
if (patchJson == null) return;
|
||||
return [
|
||||
'result',
|
||||
await client.entityaddress.update(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(entityId),
|
||||
Number(id),
|
||||
JSON.parse(patchJson),
|
||||
),
|
||||
];
|
||||
}
|
||||
case 'entityaddress.delete': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const entityId = await askInt('entity id');
|
||||
if (entityId == null) return;
|
||||
const id = await askInt('address id');
|
||||
if (id == null) return;
|
||||
await client.entityaddress.delete(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(entityId),
|
||||
Number(id),
|
||||
);
|
||||
return ['ok', true];
|
||||
}
|
||||
case 'entitycontact.list': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const entityId = await askInt('entity id');
|
||||
if (entityId == null) return;
|
||||
return [
|
||||
'result[]',
|
||||
await client.entitycontact.list(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(entityId),
|
||||
),
|
||||
];
|
||||
}
|
||||
case 'entitycontact.create': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const entityId = await askInt('entity id');
|
||||
if (entityId == null) return;
|
||||
const bodyJson = await askText('contact JSON', {
|
||||
placeholder: '{"contactType":"email","contact":"a@b.c"}',
|
||||
validate: (v) => {
|
||||
if (!v?.trim()) return 'Required';
|
||||
try {
|
||||
JSON.parse(v);
|
||||
} catch {
|
||||
return 'Invalid JSON';
|
||||
}
|
||||
},
|
||||
});
|
||||
if (bodyJson == null) return;
|
||||
return [
|
||||
'result',
|
||||
await client.entitycontact.create(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(entityId),
|
||||
JSON.parse(bodyJson),
|
||||
),
|
||||
];
|
||||
}
|
||||
case 'entitycontact.update': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const entityId = await askInt('entity id');
|
||||
if (entityId == null) return;
|
||||
const id = await askInt('contact id');
|
||||
if (id == null) return;
|
||||
const patchJson = await askText('patch JSON', {
|
||||
placeholder: '{"contact":"b@c.d"}',
|
||||
validate: (v) => {
|
||||
if (!v?.trim()) return 'Required';
|
||||
try {
|
||||
JSON.parse(v);
|
||||
} catch {
|
||||
return 'Invalid JSON';
|
||||
}
|
||||
},
|
||||
});
|
||||
if (patchJson == null) return;
|
||||
return [
|
||||
'result',
|
||||
await client.entitycontact.update(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(entityId),
|
||||
Number(id),
|
||||
JSON.parse(patchJson),
|
||||
),
|
||||
];
|
||||
}
|
||||
case 'entitycontact.delete': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const companyId = await askInt('company id');
|
||||
if (companyId == null) return;
|
||||
const entityId = await askInt('entity id');
|
||||
if (entityId == null) return;
|
||||
const id = await askInt('contact id');
|
||||
if (id == null) return;
|
||||
await client.entitycontact.delete(
|
||||
Number(googleAuthId),
|
||||
Number(companyId),
|
||||
Number(entityId),
|
||||
Number(id),
|
||||
);
|
||||
return ['ok', true];
|
||||
}
|
||||
case 'supplier.list': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
|
||||
Reference in New Issue
Block a user