u
This commit is contained in:
10
API.md
10
API.md
@@ -48,12 +48,11 @@ The store is exposed as a `LibDashStore` instance (see `src/index.js`). Each met
|
||||
- **optionslist**: `id PK`
|
||||
- **optionslistarticle**: `id PK, optionslist_id->optionslist, article_id->article, count:i=1, sort:i=0, mandated:b=0, UQ(optionslist_id, article_id), UQ(optionslist_id, sort)`
|
||||
- **pic**: `id PK, w:i, h:i, size:bi, hash:s(64) UQ, thumbw:i, thumbh:i, thumbhash:s(64), source:txt, fullbinary:bin, thumbbinary:bin`
|
||||
- **posterminal**: `id PK, company_id->company, name:s(255), token?:s(255) UQ, pairingpin:s(50)`
|
||||
- **posterminal**: `id PK, company_id->company, name:s(255), token?:s(255) UQ, pairingpin?:s(50), root_category_id?->category, sync_root_articles:b=1, lastseen_at?:dt, updated_at:dt`
|
||||
- **posterminalcategory**: `id PK, posterminal_id->posterminal, category_id->category, UQ(posterminal_id, category_id)`
|
||||
- **price**: `id PK, tax_id->tax, article_id->article, minmultiplier:d(18,4)=1, customergroup_id->customergroup, net:f`
|
||||
- **printer**: `id PK, company_id->company, address:s(255), type:s(50), model?:s(255), serial?:s(255), sort:i=0, desc?:txt`
|
||||
- **propertyname**: `id PK, company_id->company, name:s(255), sort:i=0, exclusive:b=0, UQ(company_id, name)`
|
||||
- **syncpos**: `id PK, company_id->company, paircode:s(50) UQ, token?:s(255) UQ`
|
||||
- **tax**: `id PK, rate:d(18,4) UQ`
|
||||
- **unit**: `id PK, company_id->company, si:s(50), basesi:s(50), basesifactor:f, UQ(company_id, si)`
|
||||
- **unittext**: `id PK, unit_id->unit, language_id->language, symbol:s(50), name:s(255), UQ(unit_id, language_id)`
|
||||
@@ -204,8 +203,8 @@ The store is exposed as a `LibDashStore` instance (see `src/index.js`). Each met
|
||||
- `adjust(googleAuthId: number, input: {sku?: string, warehouseId?: number, amount?: number, text?: string, externalNumber?: string, date?: string|Date, lines?: Array<object>}, tx?: object): Promise<{manifest: {id: number, number: string, type: string, date: string, createdAt: string}, lines: Array<object>, ledger: Array<object>}>`
|
||||
- [posterminal](API.posterminal.md)
|
||||
- `delete(googleAuthId: number, id: number, tx?: object): Promise<void>`
|
||||
- `findByPairingpin(pairingpin: string, tx?: object): Promise<object|null>`
|
||||
- `findByToken(token: string, tx?: object): Promise<object|null>`
|
||||
- `findByPairingpin(pairingpin: string, tx?: object): Promise<{id: number, companyId: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknowntombstoneid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}|null>`
|
||||
- `findByToken(token: string, tx?: object): Promise<{id: number, companyId: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknowntombstoneid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}|null>`
|
||||
- `getCategoryCount(input: {posterminalId: number, cursor?: number}, tx?: object): Promise<number>`
|
||||
- `getCategoryList(input: {posterminalId: number, cursor?: number, limit?: number}, tx?: object): Promise<Array<object>>`
|
||||
- `getCompositeProductCount(input: {posterminalId: number, cursor?: number}, tx?: object): Promise<number>`
|
||||
@@ -215,13 +214,14 @@ The store is exposed as a `LibDashStore` instance (see `src/index.js`). Each met
|
||||
- `getMaxOrderIdCount(input: {posterminalId: number}, tx?: object): Promise<number>`
|
||||
- `getProductCount(input: {posterminalId: number, cursor?: number}, tx?: object): Promise<number>`
|
||||
- `getProductList(input: {posterminalId: number, cursor?: number, limit?: number}, tx?: object): Promise<Array<object>>`
|
||||
- `list(googleAuthId: number, tx?: object): Promise<Array<{id: number, name: string, token: string, pairingpin: string}>>`
|
||||
- `list(googleAuthId: number, tx?: object): Promise<Array<{id: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknowntombstoneid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}>>`
|
||||
- `pair(id: number, input: {token: string, clientserial?: string, pairedAt?: string}, tx?: object): Promise<{id: number, token: string, clientserial: string|null, pairedAt: string|null}>`
|
||||
- `setMaxKnownTombstoneId(id: number, maxknowntombstoneid: number|null, tx?: object): Promise<{id: number, maxknowntombstoneid: number|null}>`
|
||||
- `setOff(googleAuthId: number, posterminalId: number, categoryId: number, tx?: object): Promise<{id: number, categoryIds: Array<number>}>`
|
||||
- `setOffAll(googleAuthId: number, posterminalId: number, tx?: object): Promise<{id: number, categoryIds: Array<number>}>`
|
||||
- `setOn(googleAuthId: number, posterminalId: number, categoryId: number, tx?: object): Promise<{id: number, categoryIds: Array<number>}>`
|
||||
- `setOnAll(googleAuthId: number, posterminalId: number, tx?: object): Promise<{id: number, categoryIds: Array<number>}>`
|
||||
- `touchLastseen(id: number, tx?: object): Promise<{id: number}>`
|
||||
- `upsert(googleAuthId: number, input: {name: string, pairingpin: string, token?: string, id?: number}, tx?: object): Promise<{id: number, name: string, token: string, pairingpin: string}>`
|
||||
- [printer](API.printer.md)
|
||||
- `create(googleAuthId: number, input: {address: string, type: string, model?: string, serial?: string, sort?: number, desc?: string}, tx?: object): Promise<{id: number, company_id: number, address: string, type: string, model: string|null, serial: string|null, sort: number, desc: string|null}>`
|
||||
|
||||
@@ -45,7 +45,7 @@ Finds a posterminal by its pairingpin.
|
||||
|
||||
**Returns**
|
||||
|
||||
`Promise<object|null>` — The posterminal row, or null if not found.
|
||||
`Promise<{id: number, companyId: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknowntombstoneid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}|null>` — The posterminal, or null if not found.
|
||||
|
||||
## `posterminal.findByToken`
|
||||
|
||||
@@ -62,7 +62,7 @@ Finds a posterminal by its auth token.
|
||||
|
||||
**Returns**
|
||||
|
||||
`Promise<object|null>` — The posterminal row, or null if not found.
|
||||
`Promise<{id: number, companyId: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknowntombstoneid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}|null>` — The posterminal, or null if not found.
|
||||
|
||||
## `posterminal.getCategoryCount`
|
||||
|
||||
@@ -250,13 +250,13 @@ Lists the posterminals of the user's selected company.
|
||||
|
||||
**Returns**
|
||||
|
||||
`Promise<Array<{id: number, name: string, token: string, pairingpin: string}>>` — The posterminals.
|
||||
`Promise<Array<{id: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknowntombstoneid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}>>` — The posterminals.
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const terminals = await store.posterminal.list(42);
|
||||
// => [{ id, name, token, pairingpin }]
|
||||
// => [{ id, name, token, pairingpin, pairedAt, clientserial, maxknowntombstoneid, rootCategoryId, syncRootArticles, lastseenAt, updatedAt }]
|
||||
```
|
||||
|
||||
## `posterminal.pair`
|
||||
@@ -416,6 +416,23 @@ const result = await store.posterminal.setOnAll(42, 5);
|
||||
// => { id, categoryIds: [...] }
|
||||
```
|
||||
|
||||
## `posterminal.touchLastseen`
|
||||
|
||||
*Source: `src/store/posterminal/touchLastseen.js`*
|
||||
|
||||
Updates lastseen_at for a POS terminal to the current timestamp.
|
||||
|
||||
**Parameters**
|
||||
|
||||
| Name | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| `id` | `number` | The posterminal id. |
|
||||
| `[tx]` | `object` | Optional transaction to run within. |
|
||||
|
||||
**Returns**
|
||||
|
||||
`Promise<{id: number}>`
|
||||
|
||||
## `posterminal.upsert`
|
||||
|
||||
*Source: `src/store/posterminal/upsert.js`*
|
||||
|
||||
@@ -111,7 +111,7 @@ Abgeleitet aus den Schemata (Eltern vor Kindern). Die Registry speichert sie exp
|
||||
6. `article` (Selbstreferenz), `articletext`, `articleean`, `articlepic`, `articleproperty`, `articleattributevalue`, `articlelistarticle`, `optionslistarticle`, `brandpic`, `categoryarticle`, `categorypic`, `categorytext`
|
||||
7. `price`, `articlesupplier`
|
||||
8. `manifest`, `manifestarticle`, `file`, `manifestattachment`, `warehouse`, `ledger`
|
||||
9. `numbers`, `companyuser`, `articlehistory`, `entityhistory`, `syncpos`, `companysetting`, `posterminal`, `posterminalcategory`, `printer`, `labeltemplate`
|
||||
9. `numbers`, `companyuser`, `articlehistory`, `entityhistory`, `companysetting`, `posterminal`, `posterminalcategory`, `printer`, `labeltemplate`
|
||||
|
||||
Selbstreferenzen (`category.parent_id`, `article.parentarticle_id`): Der Export sortiert nach `id`. Beim Import wird die FK-Prüfung zurückgestellt (§6.3), ein Zwei-Pass-Update ist nicht nötig.
|
||||
|
||||
@@ -315,7 +315,6 @@ Betroffene Felder (Registry-Flag `secret`):
|
||||
|
||||
- `google_auth`: `email`, `sub`, `picture`, `picturebinary` (personenbezogen)
|
||||
- `posterminal`: `token`, `pairingpin`
|
||||
- `syncpos`: `paircode`, `token`
|
||||
- `companysetting`: Zeilen mit `writeonly = 1` (z. B. API-Schlüssel)
|
||||
|
||||
Regeln:
|
||||
|
||||
@@ -359,12 +359,11 @@ const SCHEMA_TABLES = [
|
||||
['optionslist', 'id PK'],
|
||||
['optionslistarticle', 'id PK, optionslist_id->optionslist, article_id->article, count:i=1, sort:i=0, mandated:b=0, UQ(optionslist_id, article_id), UQ(optionslist_id, sort)'],
|
||||
['pic', 'id PK, w:i, h:i, size:bi, hash:s(64) UQ, thumbw:i, thumbh:i, thumbhash:s(64), source:txt, fullbinary:bin, thumbbinary:bin'],
|
||||
['posterminal', 'id PK, company_id->company, name:s(255), token?:s(255) UQ, pairingpin:s(50)'],
|
||||
['posterminal', 'id PK, company_id->company, name:s(255), token?:s(255) UQ, pairingpin?:s(50), root_category_id?->category, sync_root_articles:b=1, lastseen_at?:dt, updated_at:dt'],
|
||||
['posterminalcategory', 'id PK, posterminal_id->posterminal, category_id->category, UQ(posterminal_id, category_id)'],
|
||||
['price', 'id PK, tax_id->tax, article_id->article, minmultiplier:d(18,4)=1, customergroup_id->customergroup, net:f'],
|
||||
['printer', 'id PK, company_id->company, address:s(255), type:s(50), model?:s(255), serial?:s(255), sort:i=0, desc?:txt'],
|
||||
['propertyname', 'id PK, company_id->company, name:s(255), sort:i=0, exclusive:b=0, UQ(company_id, name)'],
|
||||
['syncpos', 'id PK, company_id->company, paircode:s(50) UQ, token?:s(255) UQ'],
|
||||
['tax', 'id PK, rate:d(18,4) UQ'],
|
||||
['unit', 'id PK, company_id->company, si:s(50), basesi:s(50), basesifactor:f, UQ(company_id, si)'],
|
||||
['unittext', 'id PK, unit_id->unit, language_id->language, symbol:s(50), name:s(255), UQ(unit_id, language_id)'],
|
||||
|
||||
@@ -328,7 +328,6 @@ const CLUSTERS = [
|
||||
'meta',
|
||||
'google_auth',
|
||||
'companyuser',
|
||||
'syncpos',
|
||||
'company',
|
||||
'companyhistory',
|
||||
'companysetting',
|
||||
|
||||
File diff suppressed because one or more lines are too long
2585
schema-graph.svg
2585
schema-graph.svg
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 294 KiB After Width: | Height: | Size: 294 KiB |
@@ -117,6 +117,7 @@ import posterminalGetMaxOrderIdCount from './store/posterminal/getMaxOrderIdCoun
|
||||
import posterminalGetCategoryList from './store/posterminal/getCategoryList.js';
|
||||
import posterminalGetProductList from './store/posterminal/getProductList.js';
|
||||
import posterminalSetMaxKnownTombstoneId from './store/posterminal/setMaxKnownTombstoneId.js';
|
||||
import posterminalTouchLastseen from './store/posterminal/touchLastseen.js';
|
||||
import langCreate from './store/lang/create.js';
|
||||
import langDelete from './store/lang/delete.js';
|
||||
import langList from './store/lang/list.js';
|
||||
@@ -414,6 +415,7 @@ export default class LibDashStore {
|
||||
getCategoryList: posterminalGetCategoryList(provider),
|
||||
getProductList: posterminalGetProductList(provider),
|
||||
setMaxKnownTombstoneId: posterminalSetMaxKnownTombstoneId(provider),
|
||||
touchLastseen: posterminalTouchLastseen(provider),
|
||||
};
|
||||
|
||||
this.google_auth = {
|
||||
|
||||
@@ -11,7 +11,6 @@ export const TABLES = [
|
||||
'modelmessage',
|
||||
'modelconversation',
|
||||
'companyuser',
|
||||
'syncpos',
|
||||
'companysetting',
|
||||
'posterminalcategory',
|
||||
'posterminal',
|
||||
|
||||
@@ -6,7 +6,11 @@ SELECT
|
||||
pairingpin,
|
||||
paired_at AS pairedAt,
|
||||
clientserial AS clientserial,
|
||||
maxknowntombstoneid AS maxknowntombstoneid
|
||||
maxknowntombstoneid AS maxknowntombstoneid,
|
||||
root_category_id AS rootCategoryId,
|
||||
sync_root_articles AS syncRootArticles,
|
||||
lastseen_at AS lastseenAt,
|
||||
updated_at AS updatedAt
|
||||
FROM posterminal
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY id
|
||||
@@ -21,7 +25,11 @@ SELECT
|
||||
pairingpin,
|
||||
paired_at AS pairedAt,
|
||||
clientserial AS clientserial,
|
||||
maxknowntombstoneid AS maxknowntombstoneid
|
||||
maxknowntombstoneid AS maxknowntombstoneid,
|
||||
root_category_id AS rootCategoryId,
|
||||
sync_root_articles AS syncRootArticles,
|
||||
lastseen_at AS lastseenAt,
|
||||
updated_at AS updatedAt
|
||||
FROM posterminal
|
||||
WHERE id = @id
|
||||
`;
|
||||
@@ -35,29 +43,39 @@ SELECT
|
||||
pairingpin,
|
||||
paired_at AS pairedAt,
|
||||
clientserial AS clientserial,
|
||||
maxknowntombstoneid AS maxknowntombstoneid
|
||||
maxknowntombstoneid AS maxknowntombstoneid,
|
||||
root_category_id AS rootCategoryId,
|
||||
sync_root_articles AS syncRootArticles,
|
||||
lastseen_at AS lastseenAt,
|
||||
updated_at AS updatedAt
|
||||
FROM posterminal
|
||||
WHERE pairingpin = @pairingpin
|
||||
`;
|
||||
|
||||
export const PAIR = `
|
||||
UPDATE posterminal
|
||||
SET token = @token, paired_at = @pairedAt, clientserial = @clientserial, pairingpin = ''
|
||||
SET token = @token, paired_at = @pairedAt, clientserial = @clientserial, pairingpin = NULL, lastseen_at = @pairedAt, updated_at = SYSUTCDATETIME()
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO posterminal (company_id, name, token, pairingpin, paired_at, clientserial, maxknowntombstoneid)
|
||||
OUTPUT INSERTED.id, INSERTED.name, INSERTED.token, INSERTED.pairingpin, INSERTED.paired_at AS pairedAt, INSERTED.clientserial AS clientserial, INSERTED.maxknowntombstoneid AS maxknowntombstoneid
|
||||
VALUES (@companyId, @name, @token, @pairingpin, @pairedAt, @clientserial, @maxknowntombstoneid)
|
||||
INSERT INTO posterminal (company_id, name, token, pairingpin, paired_at, clientserial, maxknowntombstoneid, root_category_id, sync_root_articles, lastseen_at, updated_at)
|
||||
OUTPUT INSERTED.id, INSERTED.name, INSERTED.token, INSERTED.pairingpin, INSERTED.paired_at AS pairedAt, INSERTED.clientserial AS clientserial, INSERTED.maxknowntombstoneid AS maxknowntombstoneid, INSERTED.root_category_id AS rootCategoryId, INSERTED.sync_root_articles AS syncRootArticles, INSERTED.lastseen_at AS lastseenAt, INSERTED.updated_at AS updatedAt
|
||||
VALUES (@companyId, @name, @token, @pairingpin, @pairedAt, @clientserial, @maxknowntombstoneid, @rootCategoryId, @syncRootArticles, @lastseenAt, SYSUTCDATETIME())
|
||||
`;
|
||||
|
||||
export const UPDATE = `
|
||||
UPDATE posterminal
|
||||
SET name = @name, token = @token, pairingpin = @pairingpin, paired_at = @pairedAt, clientserial = @clientserial, maxknowntombstoneid = @maxknowntombstoneid
|
||||
SET name = @name, token = @token, pairingpin = @pairingpin, paired_at = @pairedAt, clientserial = @clientserial, maxknowntombstoneid = @maxknowntombstoneid, root_category_id = @rootCategoryId, sync_root_articles = @syncRootArticles, lastseen_at = @lastseenAt, updated_at = SYSUTCDATETIME()
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const TOUCH_LASTSEEN = `
|
||||
UPDATE posterminal
|
||||
SET lastseen_at = SYSUTCDATETIME()
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const SET_MAX_KNOWN_TOMBSTONE_ID = `
|
||||
UPDATE posterminal
|
||||
SET maxknowntombstoneid = @maxknowntombstoneid
|
||||
@@ -132,7 +150,11 @@ SELECT
|
||||
pairingpin,
|
||||
paired_at AS pairedAt,
|
||||
clientserial AS clientserial,
|
||||
maxknowntombstoneid AS maxknowntombstoneid
|
||||
maxknowntombstoneid AS maxknowntombstoneid,
|
||||
root_category_id AS rootCategoryId,
|
||||
sync_root_articles AS syncRootArticles,
|
||||
lastseen_at AS lastseenAt,
|
||||
updated_at AS updatedAt
|
||||
FROM posterminal
|
||||
WHERE token = @token
|
||||
`;
|
||||
|
||||
@@ -840,21 +840,6 @@ BEGIN
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_SYNCPOS = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'syncpos')
|
||||
BEGIN
|
||||
CREATE TABLE syncpos (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
company_id INT NOT NULL,
|
||||
paircode NVARCHAR(50) NOT NULL,
|
||||
token NVARCHAR(255) NULL,
|
||||
CONSTRAINT FK_syncpos_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
|
||||
CONSTRAINT UQ_syncpos_paircode UNIQUE (paircode),
|
||||
CONSTRAINT UQ_syncpos_token UNIQUE (token)
|
||||
);
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_COMPANYSETTING = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'companysetting')
|
||||
BEGIN
|
||||
@@ -879,21 +864,19 @@ BEGIN
|
||||
company_id INT NOT NULL,
|
||||
name NVARCHAR(255) NOT NULL,
|
||||
token NVARCHAR(255) NULL,
|
||||
pairingpin NVARCHAR(50) NOT NULL,
|
||||
pairingpin NVARCHAR(50) NULL,
|
||||
paired_at DATETIME2 NULL,
|
||||
clientserial NVARCHAR(255) NULL,
|
||||
maxknowntombstoneid INT NULL,
|
||||
CONSTRAINT FK_posterminal_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE
|
||||
root_category_id INT NULL,
|
||||
sync_root_articles BIT NOT NULL CONSTRAINT DF_posterminal_sync_root_articles DEFAULT 1,
|
||||
lastseen_at DATETIME2 NULL,
|
||||
updated_at DATETIME2 NOT NULL CONSTRAINT DF_posterminal_updated_at DEFAULT SYSUTCDATETIME(),
|
||||
CONSTRAINT FK_posterminal_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
|
||||
CONSTRAINT FK_posterminal_root_category FOREIGN KEY (root_category_id) REFERENCES category(id) ON DELETE SET NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX UQ_posterminal_token ON posterminal(token) WHERE token IS NOT NULL;
|
||||
END
|
||||
ELSE
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('posterminal') AND name = 'maxknowntombstoneid')
|
||||
BEGIN
|
||||
ALTER TABLE posterminal ADD maxknowntombstoneid INT NULL;
|
||||
END
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_POSTERMINALCATEGORY = `
|
||||
@@ -1163,7 +1146,6 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_ARTICLETOMBSTONE,
|
||||
INIT_ENTITYHISTORY,
|
||||
INIT_COMPANYHISTORY,
|
||||
INIT_SYNCPOS,
|
||||
INIT_COMPANYSETTING,
|
||||
INIT_POSTERMINAL,
|
||||
INIT_POSTERMINALCATEGORY,
|
||||
|
||||
@@ -9,6 +9,7 @@ export const {
|
||||
FIND_BY_TOKEN, COUNT_PRODUCTS, COUNT_CATEGORIES, COUNT_CUSTOMERS,
|
||||
COUNT_CUSTOMER_GROUPS, COUNT_COMPOSITE_PRODUCTS, MAX_ORDER_ID,
|
||||
LIST_POS_PRODUCT_CATEGORIES, LIST_POS_CUSTOMER_GROUP_IDS, LIST_POS_PRODUCT_PRICES,
|
||||
TOUCH_LASTSEEN,
|
||||
} = queries;
|
||||
|
||||
export const SET_ON = `
|
||||
|
||||
@@ -578,16 +578,6 @@ CREATE TABLE IF NOT EXISTS entityhistory (
|
||||
);
|
||||
`;
|
||||
|
||||
export const INIT_SYNCPOS = `
|
||||
CREATE TABLE IF NOT EXISTS syncpos (
|
||||
id INTEGER PRIMARY KEY,
|
||||
company_id INTEGER NOT NULL,
|
||||
paircode TEXT NOT NULL UNIQUE,
|
||||
token TEXT UNIQUE,
|
||||
FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE
|
||||
);
|
||||
`;
|
||||
|
||||
export const INIT_COMPANYSETTING = `
|
||||
CREATE TABLE IF NOT EXISTS companysetting (
|
||||
id INTEGER PRIMARY KEY,
|
||||
@@ -607,11 +597,16 @@ CREATE TABLE IF NOT EXISTS posterminal (
|
||||
company_id INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
token TEXT,
|
||||
pairingpin TEXT NOT NULL,
|
||||
pairingpin TEXT,
|
||||
paired_at TEXT,
|
||||
clientserial TEXT,
|
||||
maxknowntombstoneid INTEGER,
|
||||
FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE
|
||||
root_category_id INTEGER,
|
||||
sync_root_articles INTEGER NOT NULL DEFAULT 1,
|
||||
lastseen_at TEXT,
|
||||
updated_at TEXT NOT NULL DEFAULT (${UTC_NOW}),
|
||||
FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (root_category_id) REFERENCES category(id) ON DELETE SET NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS UQ_posterminal_token
|
||||
ON posterminal(token) WHERE token IS NOT NULL;
|
||||
@@ -831,7 +826,6 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_ARTICLETOMBSTONE,
|
||||
INIT_ENTITYHISTORY,
|
||||
INIT_COMPANYHISTORY,
|
||||
INIT_SYNCPOS,
|
||||
INIT_COMPANYSETTING,
|
||||
INIT_POSTERMINAL,
|
||||
INIT_POSTERMINALCATEGORY,
|
||||
|
||||
@@ -10,7 +10,7 @@ export default function findByPairingpin(provider) {
|
||||
*
|
||||
* @param {string} pairingpin - The pairing pin to search for.
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<object|null>} The posterminal row, or null if not found.
|
||||
* @returns {Promise<{id: number, companyId: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknowntombstoneid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}|null>} The posterminal, or null if not found.
|
||||
*/
|
||||
return async (pairingpin, tx) => {
|
||||
if (!pairingpin) return null;
|
||||
|
||||
@@ -10,7 +10,7 @@ export default function findByToken(provider) {
|
||||
*
|
||||
* @param {string} token - The auth token to search for.
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<object|null>} The posterminal row, or null if not found.
|
||||
* @returns {Promise<{id: number, companyId: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknowntombstoneid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}|null>} The posterminal, or null if not found.
|
||||
*/
|
||||
return async (token, tx) => {
|
||||
const trimmed = String(token ?? '').trim();
|
||||
|
||||
@@ -12,11 +12,11 @@ export default function list(provider) {
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<Array<{id: number, name: string, token: string, pairingpin: string}>>} The posterminals.
|
||||
* @returns {Promise<Array<{id: number, name: string, token: string|null, pairingpin: string|null, pairedAt: string|null, clientserial: string|null, maxknowntombstoneid: number|null, rootCategoryId: number|null, syncRootArticles: boolean|number, lastseenAt: string|null, updatedAt: string}>>} The posterminals.
|
||||
*
|
||||
* @example
|
||||
* const terminals = await store.posterminal.list(42);
|
||||
* // => [{ id, name, token, pairingpin }]
|
||||
* // => [{ id, name, token, pairingpin, pairedAt, clientserial, maxknowntombstoneid, rootCategoryId, syncRootArticles, lastseenAt, updatedAt }]
|
||||
*/
|
||||
return async (googleAuthId, tx) => {
|
||||
const { companyId } = await access(googleAuthId, tx);
|
||||
|
||||
19
src/store/posterminal/touchLastseen.js
Normal file
19
src/store/posterminal/touchLastseen.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { TOUCH_LASTSEEN as MSSQL_TOUCH } from '../../providers/mssql/queries/posterminal.js';
|
||||
import { TOUCH_LASTSEEN as SQLITE_TOUCH } from '../../providers/sqlite3/queries/posterminal.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function touchLastseen(provider) {
|
||||
const sql = provider?.dialect === 'sqlite3' ? SQLITE_TOUCH : MSSQL_TOUCH;
|
||||
|
||||
/**
|
||||
* Updates lastseen_at for a POS terminal to the current timestamp.
|
||||
*
|
||||
* @param {number} id - The posterminal id.
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<{id: number}>}
|
||||
*/
|
||||
return async (id, tx) => {
|
||||
await makeRunner(provider, tx).query(sql, { id: Number(id) });
|
||||
return { id: Number(id) };
|
||||
};
|
||||
}
|
||||
@@ -37,16 +37,12 @@ export default function upsert(provider) {
|
||||
* // => { id, name, token, pairingpin }
|
||||
*/
|
||||
return async (googleAuthId, input = {}, tx) => {
|
||||
const name = input.name?.trim();
|
||||
if (!name) {
|
||||
throw new Error('Invalid posterminal');
|
||||
}
|
||||
const pairingpin = input.pairingpin?.trim();
|
||||
if (!pairingpin) {
|
||||
const id = input.id ?? null;
|
||||
const name = input.name !== undefined ? input.name?.trim() : undefined;
|
||||
if (name === '' || (!name && !id)) {
|
||||
throw new Error('Invalid posterminal');
|
||||
}
|
||||
const token = input.token ?? null;
|
||||
const id = input.id ?? null;
|
||||
const pairedAt = input.pairedAt ?? null;
|
||||
const clientserial = input.clientserial ?? null;
|
||||
|
||||
@@ -60,26 +56,67 @@ export default function upsert(provider) {
|
||||
throw new Error('Posterminal not found');
|
||||
}
|
||||
|
||||
const nameVal = name !== undefined ? name : existing.rows[0].name;
|
||||
|
||||
const pairingpin =
|
||||
input.pairingpin !== undefined
|
||||
? (input.pairingpin ? String(input.pairingpin).trim() : null)
|
||||
: (existing.rows[0].pairingpin ?? null);
|
||||
|
||||
const maxknowntombstoneid =
|
||||
input.maxknowntombstoneid !== undefined
|
||||
? input.maxknowntombstoneid
|
||||
: (existing.rows[0].maxknowntombstoneid ?? null);
|
||||
|
||||
const rootCategoryId =
|
||||
input.rootCategoryId !== undefined
|
||||
? (input.rootCategoryId != null ? Number(input.rootCategoryId) : null)
|
||||
: (existing.rows[0].rootCategoryId ?? null);
|
||||
|
||||
const syncRootArticles =
|
||||
input.syncRootArticles !== undefined
|
||||
? (input.syncRootArticles ? 1 : 0)
|
||||
: (existing.rows[0].syncRootArticles !== undefined ? (existing.rows[0].syncRootArticles ? 1 : 0) : 1);
|
||||
|
||||
const lastseenAt =
|
||||
input.lastseenAt !== undefined
|
||||
? input.lastseenAt
|
||||
: (existing.rows[0].lastseenAt ?? null);
|
||||
|
||||
await runner.query(updateSql, {
|
||||
id,
|
||||
companyId,
|
||||
name,
|
||||
name: nameVal,
|
||||
token,
|
||||
pairingpin,
|
||||
pairedAt,
|
||||
clientserial,
|
||||
maxknowntombstoneid,
|
||||
rootCategoryId,
|
||||
syncRootArticles,
|
||||
lastseenAt,
|
||||
});
|
||||
|
||||
return { id, name, token, pairingpin, pairedAt, clientserial, maxknowntombstoneid };
|
||||
return {
|
||||
id,
|
||||
name: nameVal,
|
||||
token,
|
||||
pairingpin,
|
||||
pairedAt,
|
||||
clientserial,
|
||||
maxknowntombstoneid,
|
||||
rootCategoryId,
|
||||
syncRootArticles,
|
||||
lastseenAt,
|
||||
};
|
||||
}
|
||||
|
||||
const pairingpin = input.pairingpin ? String(input.pairingpin).trim() : null;
|
||||
const maxknowntombstoneid = input.maxknowntombstoneid ?? null;
|
||||
const rootCategoryId = input.rootCategoryId != null ? Number(input.rootCategoryId) : null;
|
||||
const syncRootArticles = input.syncRootArticles !== undefined ? (input.syncRootArticles ? 1 : 0) : 1;
|
||||
const lastseenAt = input.lastseenAt ?? null;
|
||||
|
||||
const created = await runner.query(createSql, {
|
||||
companyId,
|
||||
name,
|
||||
@@ -88,6 +125,9 @@ export default function upsert(provider) {
|
||||
pairedAt,
|
||||
clientserial,
|
||||
maxknowntombstoneid,
|
||||
rootCategoryId,
|
||||
syncRootArticles,
|
||||
lastseenAt,
|
||||
});
|
||||
|
||||
const row = created.rows[0] ?? {
|
||||
@@ -98,16 +138,23 @@ export default function upsert(provider) {
|
||||
pairedAt,
|
||||
clientserial,
|
||||
maxknowntombstoneid,
|
||||
rootCategoryId,
|
||||
syncRootArticles,
|
||||
lastseenAt,
|
||||
};
|
||||
|
||||
return {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
token: row.token,
|
||||
pairingpin: row.pairingpin,
|
||||
pairingpin: row.pairingpin ?? null,
|
||||
pairedAt: row.pairedAt ?? null,
|
||||
clientserial: row.clientserial ?? null,
|
||||
maxknowntombstoneid: row.maxknowntombstoneid ?? null,
|
||||
rootCategoryId: row.rootCategoryId ?? null,
|
||||
syncRootArticles: row.syncRootArticles !== undefined ? (row.syncRootArticles ? 1 : 0) : 1,
|
||||
lastseenAt: row.lastseenAt ?? null,
|
||||
updatedAt: row.updatedAt ?? null,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user