Link articlehistory to companyuser; store Google picture and sub on google_auth
This commit is contained in:
@@ -61,6 +61,7 @@ import googleAuthGetByEmail from './store/google_auth/getByEmail.js';
|
||||
import googleAuthListAllowedEmails from './store/google_auth/listAllowedEmails.js';
|
||||
import googleAuthRemoveAllowedEmail from './store/google_auth/removeAllowedEmail.js';
|
||||
import googleAuthSetSelectedCompany from './store/google_auth/setSelectedCompany.js';
|
||||
import googleAuthSetProfile from './store/google_auth/setProfile.js';
|
||||
import picGetImageByHash from './store/pic/getImageByHash.js';
|
||||
import picGetThumbByHash from './store/pic/getThumbByHash.js';
|
||||
import storePurge from './store/purge.js';
|
||||
@@ -164,6 +165,7 @@ export default class LibDashStore {
|
||||
listAllowedEmails: googleAuthListAllowedEmails(pool),
|
||||
removeAllowedEmail: googleAuthRemoveAllowedEmail(pool),
|
||||
setSelectedCompany: googleAuthSetSelectedCompany(pool),
|
||||
setProfile: googleAuthSetProfile(pool),
|
||||
};
|
||||
|
||||
this.pic = {
|
||||
|
||||
@@ -21,11 +21,14 @@ BEGIN
|
||||
CREATE TABLE google_auth (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
email NVARCHAR(320) NOT NULL,
|
||||
picture NVARCHAR(2048) NULL,
|
||||
sub NVARCHAR(255) NULL,
|
||||
created_at DATETIME2 NOT NULL CONSTRAINT DF_google_auth_created_at DEFAULT SYSUTCDATETIME(),
|
||||
selected_company INT NULL,
|
||||
CONSTRAINT UQ_google_auth_email UNIQUE (email),
|
||||
CONSTRAINT FK_google_auth_selected_company FOREIGN KEY (selected_company) REFERENCES company(id) ON DELETE SET NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX UQ_google_auth_sub ON google_auth(sub) WHERE sub IS NOT NULL;
|
||||
END
|
||||
`;
|
||||
|
||||
@@ -260,9 +263,11 @@ BEGIN
|
||||
CREATE TABLE articlehistory (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
article_id INT NOT NULL,
|
||||
companyuser_id INT NULL,
|
||||
[date] DATETIME2 NOT NULL CONSTRAINT DF_articlehistory_date DEFAULT SYSUTCDATETIME(),
|
||||
[text] NVARCHAR(MAX) NOT NULL,
|
||||
CONSTRAINT FK_articlehistory_article FOREIGN KEY (article_id) REFERENCES article(id) ON DELETE CASCADE
|
||||
CONSTRAINT FK_articlehistory_article FOREIGN KEY (article_id) REFERENCES article(id) ON DELETE CASCADE,
|
||||
CONSTRAINT FK_articlehistory_companyuser FOREIGN KEY (companyuser_id) REFERENCES companyuser(id) ON DELETE SET NULL
|
||||
);
|
||||
END
|
||||
`;
|
||||
@@ -615,7 +620,6 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_ARTICLELIST,
|
||||
INIT_BRAND,
|
||||
INIT_ARTICLE,
|
||||
INIT_ARTICLEHISTORY,
|
||||
INIT_ARTICLEEAN,
|
||||
INIT_ARTICLEPIC,
|
||||
INIT_BRANDPIC,
|
||||
@@ -631,6 +635,7 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_NUMBERS,
|
||||
INIT_GET_NEXT_NUMBER_WITH_PREFIX_AND_PADDING,
|
||||
INIT_COMPANYUSER,
|
||||
INIT_ARTICLEHISTORY,
|
||||
INIT_SYNCPOS,
|
||||
INIT_COMPANYSETTING,
|
||||
INIT_POSTERMINAL,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
export const INSERT = `
|
||||
INSERT INTO articlehistory (article_id, [text])
|
||||
VALUES (@articleId, @text)
|
||||
INSERT INTO articlehistory (article_id, companyuser_id, [text])
|
||||
VALUES (@articleId, @companyuserId, @text)
|
||||
`;
|
||||
|
||||
export const LIST_BY_ARTICLE_ID = `
|
||||
SELECT id, [date], [text]
|
||||
SELECT id, companyuser_id AS companyuserId, [date], [text]
|
||||
FROM articlehistory
|
||||
WHERE article_id = @articleId
|
||||
ORDER BY [date] DESC, id DESC
|
||||
|
||||
@@ -5,13 +5,25 @@ VALUES (@email)
|
||||
`;
|
||||
|
||||
export const GET_BY_EMAIL = `
|
||||
SELECT id, email, created_at AS createdAt, selected_company AS selectedCompanyId
|
||||
SELECT
|
||||
id,
|
||||
email,
|
||||
picture,
|
||||
sub,
|
||||
created_at AS createdAt,
|
||||
selected_company AS selectedCompanyId
|
||||
FROM google_auth
|
||||
WHERE email = @email
|
||||
`;
|
||||
|
||||
export const LIST_ALLOWED_EMAILS = `
|
||||
SELECT id, email, created_at AS createdAt, selected_company AS selectedCompanyId
|
||||
SELECT
|
||||
id,
|
||||
email,
|
||||
picture,
|
||||
sub,
|
||||
created_at AS createdAt,
|
||||
selected_company AS selectedCompanyId
|
||||
FROM google_auth
|
||||
ORDER BY email
|
||||
`;
|
||||
@@ -26,3 +38,9 @@ UPDATE google_auth
|
||||
SET selected_company = @companyId
|
||||
WHERE id = @googleAuthId
|
||||
`;
|
||||
|
||||
export const SET_PROFILE = `
|
||||
UPDATE google_auth
|
||||
SET picture = @picture, sub = @sub
|
||||
WHERE id = @googleAuthId
|
||||
`;
|
||||
|
||||
@@ -14,6 +14,7 @@ export default function getHistoryBySku(pool) {
|
||||
|
||||
return result.recordset.map((row) => ({
|
||||
id: row.id,
|
||||
companyuserId: row.companyuserId ?? null,
|
||||
date: row.date,
|
||||
text: row.text,
|
||||
}));
|
||||
|
||||
@@ -26,6 +26,7 @@ export default function resolveArticleBySku(pool) {
|
||||
companyId: row.companyId,
|
||||
rootCategoryId: row.rootCategoryId,
|
||||
posCustomerGroupId: row.posCustomerGroupId ?? null,
|
||||
companyuserId: row.companyuserId,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -41,7 +41,10 @@ export default function updateBySku(pool) {
|
||||
throw new Error('Invalid unitamount');
|
||||
}
|
||||
|
||||
const { articleId, languageId, companyId } = await resolve(googleAuthId, sku);
|
||||
const { articleId, languageId, companyId, companyuserId } = await resolve(
|
||||
googleAuthId,
|
||||
sku,
|
||||
);
|
||||
|
||||
const currentResult = await pool
|
||||
.request()
|
||||
@@ -134,6 +137,7 @@ export default function updateBySku(pool) {
|
||||
if (historyLines.length) {
|
||||
await request(pool, tx)
|
||||
.input('articleId', articleId)
|
||||
.input('companyuserId', companyuserId)
|
||||
.input('text', historyLines.join('\n'))
|
||||
.query(INSERT_HISTORY);
|
||||
}
|
||||
|
||||
16
src/store/google_auth/setProfile.js
Normal file
16
src/store/google_auth/setProfile.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { SET_PROFILE } from '../../sql/google_auth.js';
|
||||
|
||||
export default function setProfile(pool) {
|
||||
return async (googleAuthId, { picture = null, sub = null } = {}) => {
|
||||
const result = await pool
|
||||
.request()
|
||||
.input('googleAuthId', googleAuthId)
|
||||
.input('picture', picture)
|
||||
.input('sub', sub)
|
||||
.query(SET_PROFILE);
|
||||
|
||||
if (!result.rowsAffected[0]) {
|
||||
throw new Error('User not found');
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user