Add name column to posterminal table
- Added required name NVARCHAR(255) NOT NULL column to posterminal schema - Updated SQL queries (LIST_BY_COMPANY, GET_BY_ID, CREATE, UPDATE) to include name - Updated upsert store method to validate and persist name - Updated README with name in method signatures and return types
This commit is contained in:
@@ -574,6 +574,7 @@ BEGIN
|
||||
CREATE TABLE posterminal (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
company_id INT NOT NULL,
|
||||
name NVARCHAR(255) NOT NULL,
|
||||
token NVARCHAR(255) NULL,
|
||||
pairingpin NVARCHAR(50) NOT NULL,
|
||||
CONSTRAINT FK_posterminal_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export const LIST_BY_COMPANY = `
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
token,
|
||||
pairingpin
|
||||
FROM posterminal
|
||||
@@ -12,6 +13,7 @@ export const GET_BY_ID = `
|
||||
SELECT
|
||||
id,
|
||||
company_id AS companyId,
|
||||
name,
|
||||
token,
|
||||
pairingpin
|
||||
FROM posterminal
|
||||
@@ -19,14 +21,14 @@ WHERE id = @id
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO posterminal (company_id, token, pairingpin)
|
||||
OUTPUT INSERTED.id, INSERTED.token, INSERTED.pairingpin
|
||||
VALUES (@companyId, @token, @pairingpin)
|
||||
INSERT INTO posterminal (company_id, name, token, pairingpin)
|
||||
OUTPUT INSERTED.id, INSERTED.name, INSERTED.token, INSERTED.pairingpin
|
||||
VALUES (@companyId, @name, @token, @pairingpin)
|
||||
`;
|
||||
|
||||
export const UPDATE = `
|
||||
UPDATE posterminal
|
||||
SET token = @token, pairingpin = @pairingpin
|
||||
SET name = @name, token = @token, pairingpin = @pairingpin
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
|
||||
@@ -5,6 +5,10 @@ export default function upsert(pool) {
|
||||
const access = resolveCompanyAccess(pool);
|
||||
|
||||
return async (googleAuthId, companyId, input = {}) => {
|
||||
const name = input.name?.trim();
|
||||
if (!name) {
|
||||
throw new Error('Invalid posterminal');
|
||||
}
|
||||
const pairingpin = input.pairingpin?.trim();
|
||||
if (!pairingpin) {
|
||||
throw new Error('Invalid posterminal');
|
||||
@@ -28,22 +32,25 @@ export default function upsert(pool) {
|
||||
.request()
|
||||
.input('id', id)
|
||||
.input('companyId', companyId)
|
||||
.input('name', name)
|
||||
.input('token', token)
|
||||
.input('pairingpin', pairingpin)
|
||||
.query(UPDATE);
|
||||
|
||||
return { id, token, pairingpin };
|
||||
return { id, name, token, pairingpin };
|
||||
}
|
||||
|
||||
const created = await pool
|
||||
.request()
|
||||
.input('companyId', companyId)
|
||||
.input('name', name)
|
||||
.input('token', token)
|
||||
.input('pairingpin', pairingpin)
|
||||
.query(CREATE);
|
||||
|
||||
return {
|
||||
id: created.recordset[0].id,
|
||||
name: created.recordset[0].name,
|
||||
token: created.recordset[0].token,
|
||||
pairingpin: created.recordset[0].pairingpin,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user