u
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import companyuserGetByEmail from './store/companyuser/getByEmail.js';
|
||||
import companyuserAdd from './store/companyuser/add.js';
|
||||
import companyuserDelete from './store/companyuser/delete.js';
|
||||
import companyGetByCompanyUserId from './store/company/getByCompanyUserId.js';
|
||||
import companyCreate from './store/company/create.js';
|
||||
import companySetDefaultLang from './store/company/setDefaultLang.js';
|
||||
@@ -8,6 +9,8 @@ import companyDelete from './store/company/delete.js';
|
||||
import companyList from './store/company/list.js';
|
||||
import categoryGetTree from './store/category/getTree.js';
|
||||
import categoryCreate from './store/category/create.js';
|
||||
import categoryUpdateParentId from './store/category/updateParentId.js';
|
||||
import categoryDelete from './store/category/delete.js';
|
||||
import langCreate from './store/lang/create.js';
|
||||
import langDelete from './store/lang/delete.js';
|
||||
import langList from './store/lang/list.js';
|
||||
@@ -24,6 +27,7 @@ export default class LibDashStore {
|
||||
this.companyuser = {
|
||||
getByEmail: companyuserGetByEmail(pool),
|
||||
add: companyuserAdd(pool),
|
||||
delete: companyuserDelete(pool),
|
||||
};
|
||||
|
||||
this.company = {
|
||||
@@ -38,6 +42,8 @@ export default class LibDashStore {
|
||||
this.category = {
|
||||
getTree: categoryGetTree(pool),
|
||||
create: categoryCreate(pool),
|
||||
updateParentId: categoryUpdateParentId(pool),
|
||||
delete: categoryDelete(pool),
|
||||
};
|
||||
|
||||
this.lang = {
|
||||
|
||||
@@ -101,6 +101,7 @@ BEGIN
|
||||
name NVARCHAR(255) NOT NULL,
|
||||
root_category_id INT NULL,
|
||||
default_language_id INT NULL,
|
||||
CONSTRAINT UQ_company_name UNIQUE (name),
|
||||
CONSTRAINT FK_company_root_category FOREIGN KEY (root_category_id) REFERENCES category(id) ON DELETE SET NULL,
|
||||
CONSTRAINT FK_company_default_language FOREIGN KEY (default_language_id) REFERENCES language(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
@@ -20,3 +20,14 @@ INSERT INTO category (parent_id, sort)
|
||||
OUTPUT INSERTED.id
|
||||
VALUES (@parentId, @sort)
|
||||
`;
|
||||
|
||||
export const UPDATE_PARENT_ID = `
|
||||
UPDATE category
|
||||
SET parent_id = @parentId
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const DELETE = `
|
||||
DELETE FROM category
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
@@ -10,9 +10,9 @@ WHERE cu.id = @companyUserId
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO company (name)
|
||||
INSERT INTO company (name, root_category_id)
|
||||
OUTPUT INSERTED.id
|
||||
VALUES (@name)
|
||||
VALUES (@name, @rootCategoryId)
|
||||
`;
|
||||
|
||||
export const LIST = `
|
||||
|
||||
@@ -10,3 +10,8 @@ INSERT INTO companyuser (google_auth_id, company_id)
|
||||
OUTPUT INSERTED.id
|
||||
VALUES (@authId, @companyId)
|
||||
`;
|
||||
|
||||
export const DELETE = `
|
||||
DELETE FROM companyuser
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
11
src/store/category/delete.js
Normal file
11
src/store/category/delete.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import sql from 'mssql';
|
||||
import { DELETE } from '../../sql/category.js';
|
||||
|
||||
export default function del(pool) {
|
||||
return async (id) => {
|
||||
await pool
|
||||
.request()
|
||||
.input('id', sql.Int, id)
|
||||
.query(DELETE);
|
||||
};
|
||||
}
|
||||
12
src/store/category/updateParentId.js
Normal file
12
src/store/category/updateParentId.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import sql from 'mssql';
|
||||
import { UPDATE_PARENT_ID } from '../../sql/category.js';
|
||||
|
||||
export default function updateParentId(pool) {
|
||||
return async (id, parentId) => {
|
||||
await pool
|
||||
.request()
|
||||
.input('id', sql.Int, id)
|
||||
.input('parentId', sql.Int, parentId)
|
||||
.query(UPDATE_PARENT_ID);
|
||||
};
|
||||
}
|
||||
@@ -1,11 +1,21 @@
|
||||
import sql from 'mssql';
|
||||
import { CREATE } from '../../sql/company.js';
|
||||
import { CREATE as CREATE_CATEGORY } from '../../sql/category.js';
|
||||
|
||||
export default function create(pool) {
|
||||
return async ({ name }) => {
|
||||
const category = await pool
|
||||
.request()
|
||||
.input('parentId', sql.Int, null)
|
||||
.input('sort', sql.Int, 0)
|
||||
.query(CREATE_CATEGORY);
|
||||
|
||||
const rootCategoryId = category.recordset[0].id;
|
||||
|
||||
const result = await pool
|
||||
.request()
|
||||
.input('name', sql.NVarChar(255), name)
|
||||
.input('rootCategoryId', sql.Int, rootCategoryId)
|
||||
.query(CREATE);
|
||||
|
||||
return result.recordset[0].id;
|
||||
|
||||
11
src/store/companyuser/delete.js
Normal file
11
src/store/companyuser/delete.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import sql from 'mssql';
|
||||
import { DELETE } from '../../sql/companyuser.js';
|
||||
|
||||
export default function del(pool) {
|
||||
return async (id) => {
|
||||
await pool
|
||||
.request()
|
||||
.input('id', sql.Int, id)
|
||||
.query(DELETE);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user