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:
@@ -188,8 +188,8 @@ Company-scoped POS terminals. Auth via `resolveCompanyAccess`.
|
|||||||
|
|
||||||
| Method | Signature | Returns |
|
| Method | Signature | Returns |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `list` | `(googleAuthId, companyId)` | `{ id, token, pairingpin }[]` |
|
| `list` | `(googleAuthId, companyId)` | `{ id, name, token, pairingpin }[]` |
|
||||||
| `upsert` | `(googleAuthId, companyId, { id?, token?, pairingpin })` | `{ id, token, pairingpin }` |
|
| `upsert` | `(googleAuthId, companyId, { id?, name, token?, pairingpin })` | `{ id, name, token, pairingpin }` |
|
||||||
| `delete` | `(googleAuthId, companyId, id)` | `void` |
|
| `delete` | `(googleAuthId, companyId, id)` | `void` |
|
||||||
| `setOn` | `(googleAuthId, companyId, posterminalId, categoryId)` | `{ id, categoryIds[] }` |
|
| `setOn` | `(googleAuthId, companyId, posterminalId, categoryId)` | `{ id, categoryIds[] }` |
|
||||||
| `setOff` | `(googleAuthId, companyId, posterminalId, categoryId)` | `{ id, categoryIds[] }` |
|
| `setOff` | `(googleAuthId, companyId, posterminalId, categoryId)` | `{ id, categoryIds[] }` |
|
||||||
@@ -197,7 +197,7 @@ Company-scoped POS terminals. Auth via `resolveCompanyAccess`.
|
|||||||
| `setOffAll` | `(googleAuthId, companyId, posterminalId)` | `{ id, categoryIds[] }` |
|
| `setOffAll` | `(googleAuthId, companyId, posterminalId)` | `{ id, categoryIds[] }` |
|
||||||
| `getCategoryPosterminalIds` | `(companyId)` | `{ [categoryId]: posterminalId[] }` (internal, used by category tree) |
|
| `getCategoryPosterminalIds` | `(companyId)` | `{ [categoryId]: posterminalId[] }` (internal, used by category tree) |
|
||||||
|
|
||||||
`posterminal.company_id` **NOT NULL**. `token` is nullable and unique (pairing code assigned during setup). `pairingpin` is required.
|
`posterminal.company_id` **NOT NULL**. `name` is required. `token` is nullable and unique (pairing code assigned during setup). `pairingpin` is required.
|
||||||
|
|
||||||
`upsert`: if `id` is provided, updates the existing posterminal (must belong to company); otherwise creates a new one. Errors: `Company not found`, `Not authorized`, `Invalid posterminal`, `Posterminal not found`.
|
`upsert`: if `id` is provided, updates the existing posterminal (must belong to company); otherwise creates a new one. Errors: `Company not found`, `Not authorized`, `Invalid posterminal`, `Posterminal not found`.
|
||||||
|
|
||||||
@@ -367,7 +367,7 @@ res.set('Content-Type', thumb.contentType).send(thumb.buffer);
|
|||||||
| `PUT /api/brand` | `brand.upsert(googleAuthId, companyId, { name, gsprpinfo? })` |
|
| `PUT /api/brand` | `brand.upsert(googleAuthId, companyId, { name, gsprpinfo? })` |
|
||||||
| `DELETE /api/brand/:id` | `brand.delete(googleAuthId, companyId, id)` |
|
| `DELETE /api/brand/:id` | `brand.delete(googleAuthId, companyId, id)` |
|
||||||
| `GET /api/posterminal` | `posterminal.list(googleAuthId, companyId)` |
|
| `GET /api/posterminal` | `posterminal.list(googleAuthId, companyId)` |
|
||||||
| `PUT /api/posterminal` | `posterminal.upsert(googleAuthId, companyId, { id?, token?, pairingpin })` |
|
| `PUT /api/posterminal` | `posterminal.upsert(googleAuthId, companyId, { id?, name, token?, pairingpin })` |
|
||||||
| `DELETE /api/posterminal/:id` | `posterminal.delete(googleAuthId, companyId, id)` |
|
| `DELETE /api/posterminal/:id` | `posterminal.delete(googleAuthId, companyId, id)` |
|
||||||
| `PUT /api/posterminal/:id/category/:categoryId` | `posterminal.setOn(googleAuthId, companyId, id, categoryId)` |
|
| `PUT /api/posterminal/:id/category/:categoryId` | `posterminal.setOn(googleAuthId, companyId, id, categoryId)` |
|
||||||
| `DELETE /api/posterminal/:id/category/:categoryId` | `posterminal.setOff(googleAuthId, companyId, id, categoryId)` |
|
| `DELETE /api/posterminal/:id/category/:categoryId` | `posterminal.setOff(googleAuthId, companyId, id, categoryId)` |
|
||||||
|
|||||||
@@ -574,6 +574,7 @@ BEGIN
|
|||||||
CREATE TABLE posterminal (
|
CREATE TABLE posterminal (
|
||||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||||
company_id INT NOT NULL,
|
company_id INT NOT NULL,
|
||||||
|
name NVARCHAR(255) NOT NULL,
|
||||||
token NVARCHAR(255) NULL,
|
token NVARCHAR(255) NULL,
|
||||||
pairingpin NVARCHAR(50) NOT NULL,
|
pairingpin NVARCHAR(50) NOT NULL,
|
||||||
CONSTRAINT FK_posterminal_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
|
CONSTRAINT FK_posterminal_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const LIST_BY_COMPANY = `
|
export const LIST_BY_COMPANY = `
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
|
name,
|
||||||
token,
|
token,
|
||||||
pairingpin
|
pairingpin
|
||||||
FROM posterminal
|
FROM posterminal
|
||||||
@@ -12,6 +13,7 @@ export const GET_BY_ID = `
|
|||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
company_id AS companyId,
|
company_id AS companyId,
|
||||||
|
name,
|
||||||
token,
|
token,
|
||||||
pairingpin
|
pairingpin
|
||||||
FROM posterminal
|
FROM posterminal
|
||||||
@@ -19,14 +21,14 @@ WHERE id = @id
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const CREATE = `
|
export const CREATE = `
|
||||||
INSERT INTO posterminal (company_id, token, pairingpin)
|
INSERT INTO posterminal (company_id, name, token, pairingpin)
|
||||||
OUTPUT INSERTED.id, INSERTED.token, INSERTED.pairingpin
|
OUTPUT INSERTED.id, INSERTED.name, INSERTED.token, INSERTED.pairingpin
|
||||||
VALUES (@companyId, @token, @pairingpin)
|
VALUES (@companyId, @name, @token, @pairingpin)
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const UPDATE = `
|
export const UPDATE = `
|
||||||
UPDATE posterminal
|
UPDATE posterminal
|
||||||
SET token = @token, pairingpin = @pairingpin
|
SET name = @name, token = @token, pairingpin = @pairingpin
|
||||||
WHERE id = @id AND company_id = @companyId
|
WHERE id = @id AND company_id = @companyId
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ export default function upsert(pool) {
|
|||||||
const access = resolveCompanyAccess(pool);
|
const access = resolveCompanyAccess(pool);
|
||||||
|
|
||||||
return async (googleAuthId, companyId, input = {}) => {
|
return async (googleAuthId, companyId, input = {}) => {
|
||||||
|
const name = input.name?.trim();
|
||||||
|
if (!name) {
|
||||||
|
throw new Error('Invalid posterminal');
|
||||||
|
}
|
||||||
const pairingpin = input.pairingpin?.trim();
|
const pairingpin = input.pairingpin?.trim();
|
||||||
if (!pairingpin) {
|
if (!pairingpin) {
|
||||||
throw new Error('Invalid posterminal');
|
throw new Error('Invalid posterminal');
|
||||||
@@ -28,22 +32,25 @@ export default function upsert(pool) {
|
|||||||
.request()
|
.request()
|
||||||
.input('id', id)
|
.input('id', id)
|
||||||
.input('companyId', companyId)
|
.input('companyId', companyId)
|
||||||
|
.input('name', name)
|
||||||
.input('token', token)
|
.input('token', token)
|
||||||
.input('pairingpin', pairingpin)
|
.input('pairingpin', pairingpin)
|
||||||
.query(UPDATE);
|
.query(UPDATE);
|
||||||
|
|
||||||
return { id, token, pairingpin };
|
return { id, name, token, pairingpin };
|
||||||
}
|
}
|
||||||
|
|
||||||
const created = await pool
|
const created = await pool
|
||||||
.request()
|
.request()
|
||||||
.input('companyId', companyId)
|
.input('companyId', companyId)
|
||||||
|
.input('name', name)
|
||||||
.input('token', token)
|
.input('token', token)
|
||||||
.input('pairingpin', pairingpin)
|
.input('pairingpin', pairingpin)
|
||||||
.query(CREATE);
|
.query(CREATE);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: created.recordset[0].id,
|
id: created.recordset[0].id,
|
||||||
|
name: created.recordset[0].name,
|
||||||
token: created.recordset[0].token,
|
token: created.recordset[0].token,
|
||||||
pairingpin: created.recordset[0].pairingpin,
|
pairingpin: created.recordset[0].pairingpin,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user