u
This commit is contained in:
69
src/providers/mssql/queries/agentprinter.js
Normal file
69
src/providers/mssql/queries/agentprinter.js
Normal file
@@ -0,0 +1,69 @@
|
||||
export const AGENTPRINTER_COLUMNS = `
|
||||
ap.id,
|
||||
ap.printeragent_id AS printeragentId,
|
||||
ap.type,
|
||||
ap.model,
|
||||
ap.serial,
|
||||
ap.enabled,
|
||||
ap.sort
|
||||
`;
|
||||
|
||||
export const LIST_BY_COMPANY = `
|
||||
SELECT
|
||||
${AGENTPRINTER_COLUMNS}
|
||||
FROM agentprinter ap
|
||||
JOIN printeragent pa ON pa.id = ap.printeragent_id
|
||||
WHERE pa.company_id = @companyId
|
||||
ORDER BY ap.sort, ap.id
|
||||
`;
|
||||
|
||||
export const LIST_BY_PRINTERAGENT = `
|
||||
SELECT
|
||||
${AGENTPRINTER_COLUMNS}
|
||||
FROM agentprinter ap
|
||||
JOIN printeragent pa ON pa.id = ap.printeragent_id
|
||||
WHERE ap.printeragent_id = @printeragentId AND pa.company_id = @companyId
|
||||
ORDER BY ap.sort, ap.id
|
||||
`;
|
||||
|
||||
export const GET_BY_ID = `
|
||||
SELECT
|
||||
${AGENTPRINTER_COLUMNS}
|
||||
FROM agentprinter ap
|
||||
JOIN printeragent pa ON pa.id = ap.printeragent_id
|
||||
WHERE ap.id = @id AND pa.company_id = @companyId
|
||||
`;
|
||||
|
||||
export const FIND_BY_COMBO = `
|
||||
SELECT
|
||||
${AGENTPRINTER_COLUMNS}
|
||||
FROM agentprinter ap
|
||||
WHERE ap.printeragent_id = @printeragentId
|
||||
AND ap.type = @type
|
||||
AND (ap.serial = @serial OR (ap.serial IS NULL AND @serial IS NULL))
|
||||
AND (ap.model = @model OR (ap.model IS NULL AND @model IS NULL))
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO agentprinter (printeragent_id, type, model, serial, enabled, sort)
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.printeragent_id AS printeragentId,
|
||||
INSERTED.type,
|
||||
INSERTED.model,
|
||||
INSERTED.serial,
|
||||
INSERTED.enabled,
|
||||
INSERTED.sort
|
||||
VALUES (@printeragentId, @type, @model, @serial, @enabled, @sort)
|
||||
`;
|
||||
|
||||
export const UPDATE = `
|
||||
UPDATE agentprinter
|
||||
SET enabled = @enabled, sort = @sort
|
||||
WHERE id = @id AND printeragent_id IN (SELECT id FROM printeragent WHERE company_id = @companyId)
|
||||
`;
|
||||
|
||||
export const DELETE_BY_COMPANY_AND_ID = `
|
||||
DELETE FROM agentprinter
|
||||
WHERE id = @id AND printeragent_id IN (SELECT id FROM printeragent WHERE company_id = @companyId)
|
||||
`;
|
||||
@@ -5,13 +5,11 @@ export const PRINTERAGENT_COLUMNS = `
|
||||
token,
|
||||
pairingpin,
|
||||
paired_at AS pairedAt,
|
||||
clientserial,
|
||||
clientmodel,
|
||||
clientstate,
|
||||
agentversion,
|
||||
lastseen_at AS lastseenAt,
|
||||
updated_at AS updatedAt,
|
||||
sort
|
||||
sort,
|
||||
enabled
|
||||
`;
|
||||
|
||||
export const LIST_BY_COMPANY = `
|
||||
@@ -55,8 +53,6 @@ UPDATE printeragent
|
||||
SET token = @token,
|
||||
pairingpin = NULL,
|
||||
paired_at = @pairedAt,
|
||||
clientserial = @clientserial,
|
||||
clientmodel = @clientmodel,
|
||||
agentversion = @agentversion,
|
||||
lastseen_at = SYSUTCDATETIME(),
|
||||
updated_at = SYSUTCDATETIME()
|
||||
@@ -85,7 +81,7 @@ WHERE id = @id
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO printeragent (company_id, name, pairingpin, sort)
|
||||
INSERT INTO printeragent (company_id, name, pairingpin, sort, enabled)
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.company_id AS companyId,
|
||||
@@ -93,19 +89,17 @@ OUTPUT
|
||||
INSERTED.token,
|
||||
INSERTED.pairingpin,
|
||||
INSERTED.paired_at AS pairedAt,
|
||||
INSERTED.clientserial,
|
||||
INSERTED.clientmodel,
|
||||
INSERTED.clientstate,
|
||||
INSERTED.agentversion,
|
||||
INSERTED.lastseen_at AS lastseenAt,
|
||||
INSERTED.updated_at AS updatedAt,
|
||||
INSERTED.sort
|
||||
VALUES (@companyId, @name, @pairingpin, @sort)
|
||||
INSERTED.sort,
|
||||
INSERTED.enabled
|
||||
VALUES (@companyId, @name, @pairingpin, @sort, @enabled)
|
||||
`;
|
||||
|
||||
export const UPDATE = `
|
||||
UPDATE printeragent
|
||||
SET name = @name, sort = @sort, updated_at = SYSUTCDATETIME()
|
||||
SET name = @name, sort = @sort, enabled = @enabled, updated_at = SYSUTCDATETIME()
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user