u
This commit is contained in:
@@ -6,6 +6,7 @@ import companyUpdate from './store/company/update.js';
|
||||
import companyDelete from './store/company/delete.js';
|
||||
import companyList from './store/company/list.js';
|
||||
import categoryGetTreeForCompany from './store/category/getTreeForCompany.js';
|
||||
import categoryGetCategoryArticles from './store/category/getCategoryArticles.js';
|
||||
import categoryCreateUnderParent from './store/category/createUnderParent.js';
|
||||
import categoryDelete from './store/category/delete.js';
|
||||
import langCreate from './store/lang/create.js';
|
||||
@@ -44,6 +45,7 @@ export default class LibDashStore {
|
||||
|
||||
this.category = {
|
||||
getTreeForCompany: categoryGetTreeForCompany(pool),
|
||||
getCategoryArticles: categoryGetCategoryArticles(pool),
|
||||
createUnderParent: categoryCreateUnderParent(pool),
|
||||
delete: categoryDelete(pool),
|
||||
};
|
||||
|
||||
@@ -518,6 +518,21 @@ 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
|
||||
`;
|
||||
|
||||
/** DDL scripts in dependency order for schema init. */
|
||||
export const SCHEMA_SCRIPTS = [
|
||||
INIT_META,
|
||||
@@ -552,4 +567,5 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_NUMBERS,
|
||||
INIT_GET_NEXT_NUMBER_WITH_PREFIX_AND_PADDING,
|
||||
INIT_COMPANYUSER,
|
||||
INIT_SYNCPOS,
|
||||
];
|
||||
|
||||
@@ -31,7 +31,7 @@ LEFT JOIN pic p ON p.id = first_pic.pic_id
|
||||
ORDER BY t.sort, t.id
|
||||
`;
|
||||
|
||||
export const GET_ROOT_CATEGORY_ARTICLES = `
|
||||
export const GET_CATEGORY_ARTICLES = `
|
||||
SELECT
|
||||
a.id,
|
||||
a.sku,
|
||||
@@ -79,7 +79,7 @@ OUTER APPLY (
|
||||
ORDER BY ap.sort ASC, ap.id ASC
|
||||
) first_pic
|
||||
LEFT JOIN pic ON pic.id = first_pic.pic_id
|
||||
WHERE ca.category_id = @rootCategoryId
|
||||
WHERE ca.category_id = @categoryId
|
||||
ORDER BY a.id
|
||||
`;
|
||||
|
||||
@@ -111,6 +111,7 @@ SELECT
|
||||
r.rootCategoryId,
|
||||
co.id AS companyId,
|
||||
co.default_language_id AS languageId,
|
||||
co.poscustomergroup_id AS posCustomerGroupId,
|
||||
cu.id AS companyuserId
|
||||
FROM category p
|
||||
LEFT JOIN root r ON 1 = 1
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/** Drop order = reverse of schema create dependency order. */
|
||||
export const TABLES = [
|
||||
'companyuser',
|
||||
'syncpos',
|
||||
'numbers',
|
||||
'manifestarticle',
|
||||
'manifest',
|
||||
|
||||
16
src/store/category/getCategoryArticles.js
Normal file
16
src/store/category/getCategoryArticles.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import resolveCategoryAccess from './resolveCategoryAccess.js';
|
||||
import queryCategoryArticles from './queryCategoryArticles.js';
|
||||
|
||||
export default function getCategoryArticles(pool) {
|
||||
const access = resolveCategoryAccess(pool);
|
||||
const articles = queryCategoryArticles(pool);
|
||||
|
||||
return async (googleAuthId, categoryId) => {
|
||||
const { languageId, posCustomerGroupId } = await access(
|
||||
googleAuthId,
|
||||
categoryId,
|
||||
);
|
||||
|
||||
return articles({ categoryId, languageId, posCustomerGroupId });
|
||||
};
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
import {
|
||||
GET_ROOT_CATEGORY_ARTICLES,
|
||||
GET_TREE_FOR_COMPANY,
|
||||
} from '../../sql/category.js';
|
||||
import { GET_TREE_FOR_COMPANY } from '../../sql/category.js';
|
||||
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
|
||||
import queryCategoryArticles from './queryCategoryArticles.js';
|
||||
|
||||
export default function getTreeForCompany(pool) {
|
||||
const access = resolveCompanyAccess(pool);
|
||||
const articles = queryCategoryArticles(pool);
|
||||
|
||||
return async (googleAuthId, companyId) => {
|
||||
const { rootCategoryId, languageId, posCustomerGroupId } = await access(
|
||||
@@ -13,24 +12,19 @@ export default function getTreeForCompany(pool) {
|
||||
companyId,
|
||||
);
|
||||
|
||||
const [treeResult, articlesResult] = await Promise.all([
|
||||
const [treeResult, articleRows] = await Promise.all([
|
||||
pool
|
||||
.request()
|
||||
.input('rootId', rootCategoryId)
|
||||
.input('languageId', languageId)
|
||||
.query(GET_TREE_FOR_COMPANY),
|
||||
pool
|
||||
.request()
|
||||
.input('rootCategoryId', rootCategoryId)
|
||||
.input('languageId', languageId)
|
||||
.input('posCustomerGroupId', posCustomerGroupId)
|
||||
.query(GET_ROOT_CATEGORY_ARTICLES),
|
||||
articles({ categoryId: rootCategoryId, languageId, posCustomerGroupId }),
|
||||
]);
|
||||
|
||||
return {
|
||||
languageId,
|
||||
tree: treeResult.recordset,
|
||||
articles: articlesResult.recordset,
|
||||
articles: articleRows,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
14
src/store/category/queryCategoryArticles.js
Normal file
14
src/store/category/queryCategoryArticles.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { GET_CATEGORY_ARTICLES } from '../../sql/category.js';
|
||||
|
||||
export default function queryCategoryArticles(pool) {
|
||||
return async ({ categoryId, languageId, posCustomerGroupId }) => {
|
||||
const result = await pool
|
||||
.request()
|
||||
.input('categoryId', categoryId)
|
||||
.input('languageId', languageId)
|
||||
.input('posCustomerGroupId', posCustomerGroupId)
|
||||
.query(GET_CATEGORY_ARTICLES);
|
||||
|
||||
return result.recordset;
|
||||
};
|
||||
}
|
||||
@@ -23,6 +23,7 @@ export default function resolveCategoryAccess(pool) {
|
||||
companyId: row.companyId,
|
||||
rootCategoryId: row.rootCategoryId,
|
||||
languageId: row.languageId,
|
||||
posCustomerGroupId: row.posCustomerGroupId ?? null,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user