Add entity address/contact tables and CRUD for entity resources
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
export const CREATE = `
|
||||
INSERT INTO customergroup (name, company_id)
|
||||
OUTPUT INSERTED.id
|
||||
OUTPUT INSERTED.id, INSERTED.name
|
||||
VALUES (@name, @companyId)
|
||||
`;
|
||||
|
||||
@@ -17,7 +17,32 @@ WHERE id = @id
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_NAME = `
|
||||
SELECT id
|
||||
SELECT id, name
|
||||
FROM customergroup
|
||||
WHERE company_id = @companyId AND name = @name
|
||||
`;
|
||||
|
||||
export const LIST_BY_COMPANY = `
|
||||
SELECT id, name
|
||||
FROM customergroup
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY name, id
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_ID = `
|
||||
SELECT id, name
|
||||
FROM customergroup
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const UPDATE_NAME = `
|
||||
UPDATE customergroup
|
||||
SET name = @name
|
||||
OUTPUT INSERTED.id, INSERTED.name
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const DELETE_BY_COMPANY_AND_ID = `
|
||||
DELETE FROM customergroup
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
export const SUPPLIER_GROUP_NAME = 'Lieferanten';
|
||||
|
||||
export const ENTITY_COLUMNS = `
|
||||
e.id,
|
||||
e.customergroup_id AS customergroupId,
|
||||
e.first_name AS firstName,
|
||||
e.name,
|
||||
e.created_at AS createdAt,
|
||||
e.updated_at AS updatedAt
|
||||
`;
|
||||
|
||||
export const LIST_BY_COMPANY = `
|
||||
SELECT
|
||||
${ENTITY_COLUMNS}
|
||||
FROM entity e
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
WHERE cg.company_id = @companyId
|
||||
ORDER BY e.name, e.id
|
||||
`;
|
||||
|
||||
export const LIST_BY_COMPANY_AND_GROUP = `
|
||||
SELECT
|
||||
${ENTITY_COLUMNS}
|
||||
FROM entity e
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
WHERE cg.company_id = @companyId
|
||||
AND e.customergroup_id = @customergroupId
|
||||
ORDER BY e.name, e.id
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_ID = `
|
||||
SELECT
|
||||
${ENTITY_COLUMNS}
|
||||
FROM entity e
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
WHERE e.id = @id
|
||||
AND cg.company_id = @companyId
|
||||
`;
|
||||
|
||||
export const LIST_SUPPLIERS_BY_COMPANY = `
|
||||
SELECT
|
||||
e.id,
|
||||
@@ -27,9 +64,31 @@ WHERE e.id = @id
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO entity (customergroup_id, name)
|
||||
OUTPUT INSERTED.id, INSERTED.name, INSERTED.created_at AS createdAt, INSERTED.updated_at AS updatedAt
|
||||
VALUES (@customergroupId, @name)
|
||||
INSERT INTO entity (customergroup_id, first_name, name)
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.customergroup_id AS customergroupId,
|
||||
INSERTED.first_name AS firstName,
|
||||
INSERTED.name,
|
||||
INSERTED.created_at AS createdAt,
|
||||
INSERTED.updated_at AS updatedAt
|
||||
VALUES (@customergroupId, @firstName, @name)
|
||||
`;
|
||||
|
||||
export const UPDATE = `
|
||||
UPDATE entity
|
||||
SET
|
||||
first_name = @firstName,
|
||||
name = @name,
|
||||
updated_at = SYSUTCDATETIME()
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.customergroup_id AS customergroupId,
|
||||
INSERTED.first_name AS firstName,
|
||||
INSERTED.name,
|
||||
INSERTED.created_at AS createdAt,
|
||||
INSERTED.updated_at AS updatedAt
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const UPDATE_NAME = `
|
||||
@@ -40,6 +99,14 @@ WHERE id = @id
|
||||
AND customergroup_id = @customergroupId
|
||||
`;
|
||||
|
||||
export const DELETE_BY_COMPANY_AND_ID = `
|
||||
DELETE e
|
||||
FROM entity e
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
WHERE e.id = @id
|
||||
AND cg.company_id = @companyId
|
||||
`;
|
||||
|
||||
export const DELETE_BY_ID = `
|
||||
DELETE e
|
||||
FROM entity e
|
||||
|
||||
93
src/sql/entityaddress.js
Normal file
93
src/sql/entityaddress.js
Normal file
@@ -0,0 +1,93 @@
|
||||
export const ADDRESS_COLUMNS = `
|
||||
id,
|
||||
entity_id AS entityId,
|
||||
first_name AS firstName,
|
||||
name,
|
||||
street,
|
||||
streetnumber AS streetNumber,
|
||||
zip,
|
||||
city,
|
||||
county,
|
||||
addresstype AS addressType
|
||||
`;
|
||||
|
||||
export const LIST_BY_ENTITY = `
|
||||
SELECT
|
||||
${ADDRESS_COLUMNS}
|
||||
FROM entityaddress
|
||||
WHERE entity_id = @entityId
|
||||
ORDER BY id
|
||||
`;
|
||||
|
||||
export const GET_BY_ENTITY_AND_ID = `
|
||||
SELECT
|
||||
${ADDRESS_COLUMNS}
|
||||
FROM entityaddress
|
||||
WHERE id = @id AND entity_id = @entityId
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO entityaddress (
|
||||
entity_id,
|
||||
first_name,
|
||||
name,
|
||||
street,
|
||||
streetnumber,
|
||||
zip,
|
||||
city,
|
||||
county,
|
||||
addresstype
|
||||
)
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.entity_id AS entityId,
|
||||
INSERTED.first_name AS firstName,
|
||||
INSERTED.name,
|
||||
INSERTED.street,
|
||||
INSERTED.streetnumber AS streetNumber,
|
||||
INSERTED.zip,
|
||||
INSERTED.city,
|
||||
INSERTED.county,
|
||||
INSERTED.addresstype AS addressType
|
||||
VALUES (
|
||||
@entityId,
|
||||
@firstName,
|
||||
@name,
|
||||
@street,
|
||||
@streetNumber,
|
||||
@zip,
|
||||
@city,
|
||||
@county,
|
||||
@addressType
|
||||
)
|
||||
`;
|
||||
|
||||
export const UPDATE = `
|
||||
UPDATE entityaddress
|
||||
SET
|
||||
first_name = @firstName,
|
||||
name = @name,
|
||||
street = @street,
|
||||
streetnumber = @streetNumber,
|
||||
zip = @zip,
|
||||
city = @city,
|
||||
county = @county,
|
||||
addresstype = @addressType
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.entity_id AS entityId,
|
||||
INSERTED.first_name AS firstName,
|
||||
INSERTED.name,
|
||||
INSERTED.street,
|
||||
INSERTED.streetnumber AS streetNumber,
|
||||
INSERTED.zip,
|
||||
INSERTED.city,
|
||||
INSERTED.county,
|
||||
INSERTED.addresstype AS addressType
|
||||
WHERE id = @id AND entity_id = @entityId
|
||||
`;
|
||||
|
||||
export const DELETE_BY_ENTITY_AND_ID = `
|
||||
DELETE FROM entityaddress
|
||||
WHERE id = @id AND entity_id = @entityId
|
||||
`;
|
||||
47
src/sql/entitycontact.js
Normal file
47
src/sql/entitycontact.js
Normal file
@@ -0,0 +1,47 @@
|
||||
export const CONTACT_COLUMNS = `
|
||||
id,
|
||||
entity_id AS entityId,
|
||||
contacttype AS contactType,
|
||||
contact
|
||||
`;
|
||||
|
||||
export const LIST_BY_ENTITY = `
|
||||
SELECT
|
||||
${CONTACT_COLUMNS}
|
||||
FROM entitycontact
|
||||
WHERE entity_id = @entityId
|
||||
ORDER BY id
|
||||
`;
|
||||
|
||||
export const GET_BY_ENTITY_AND_ID = `
|
||||
SELECT
|
||||
${CONTACT_COLUMNS}
|
||||
FROM entitycontact
|
||||
WHERE id = @id AND entity_id = @entityId
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO entitycontact (entity_id, contacttype, contact)
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.entity_id AS entityId,
|
||||
INSERTED.contacttype AS contactType,
|
||||
INSERTED.contact
|
||||
VALUES (@entityId, @contactType, @contact)
|
||||
`;
|
||||
|
||||
export const UPDATE = `
|
||||
UPDATE entitycontact
|
||||
SET contacttype = @contactType, contact = @contact
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.entity_id AS entityId,
|
||||
INSERTED.contacttype AS contactType,
|
||||
INSERTED.contact
|
||||
WHERE id = @id AND entity_id = @entityId
|
||||
`;
|
||||
|
||||
export const DELETE_BY_ENTITY_AND_ID = `
|
||||
DELETE FROM entitycontact
|
||||
WHERE id = @id AND entity_id = @entityId
|
||||
`;
|
||||
@@ -20,6 +20,8 @@ export const TABLES = [
|
||||
'articleean',
|
||||
'articlehistory',
|
||||
'entityhistory',
|
||||
'entityaddress',
|
||||
'entitycontact',
|
||||
'article',
|
||||
'brand',
|
||||
'articlelist',
|
||||
|
||||
Reference in New Issue
Block a user