Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yafangsuo_dataServer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
node_server
yafangsuo_dataServer
Commits
62b04a20
Commit
62b04a20
authored
Aug 29, 2023
by
lixinming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug
parent
b6b32be9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
10 deletions
+11
-10
user.ts
src/middleware/user.ts
+4
-3
sqlModelBind.ts
src/model/sqlModelBind.ts
+7
-7
No files found.
src/middleware/user.ts
View file @
62b04a20
...
...
@@ -2,7 +2,7 @@ import { ERRORENUM } from "../config/errorEnum";
import
{
systemConfig
}
from
"../config/serverConfig"
;
import
{
EccTableConfig
}
from
"../config/mongoTableConfig"
;
import
{
BizError
}
from
"../util/bizError"
;
import
{
m
odelMap
}
from
"../model/m
odelBind"
;
import
{
m
ysqlModelMap
}
from
"../model/sqlM
odelBind"
;
/**
* 中间件 校验连接对象token
...
...
@@ -41,8 +41,8 @@ export async function checkMySqlSign(req, res, next) {
if
(
sign
!=
systemConfig
.
sign
)
return
next
(
new
BizError
(
ERRORENUM
.
身份验证失败
,
`传入的sign值为:
${
sign
}
`
)
);
if
(
!
table
)
return
next
(
new
BizError
(
ERRORENUM
.
缺少必要参数
_
表名
,
`传入的table值为:
${
table
}
`
)
);
if
(
!
modelMap
[
table
])
return
next
(
new
BizError
(
ERRORENUM
.
不存在表
,
`传入的table值为:
${
table
}
`
)
);
req
.
tableModel
=
modelMap
[
table
];
if
(
!
m
ysqlM
odelMap
[
table
])
return
next
(
new
BizError
(
ERRORENUM
.
不存在表
,
`传入的table值为:
${
table
}
`
)
);
req
.
tableModel
=
m
ysqlM
odelMap
[
table
];
next
();
}
\ No newline at end of file
src/model/sqlModelBind.ts
View file @
62b04a20
...
...
@@ -5,7 +5,7 @@
import
{
TablesConfig
}
from
"../config/mysqlTableConfig"
;
import
{
mysqlDB
}
from
"../db/mysql/mysqlInit"
;
let
baseDB
=
{};
let
mysqlModelMap
=
{};
export
async
function
initMysqlModel
()
{
...
...
@@ -20,7 +20,7 @@ export async function initMysqlModel() {
let
model
=
mysqlDB
.
define
(
tableName
,
schema
,
schemaConf
);
baseDB
[
tableName
]
=
await
model
.
sync
({}).
then
();
mysqlModelMap
[
tableName
]
=
await
model
.
sync
({}).
then
();
}
...
...
@@ -31,11 +31,11 @@ export async function initMysqlModel() {
if
(
item
)
{
let
{
type
,
check
}
=
item
;
if
(
type
==
"hasOne"
)
{
baseDB
[
check
].
hasOne
(
baseDB
[
tableName
]);
mysqlModelMap
[
check
].
hasOne
(
mysqlModelMap
[
tableName
]);
}
else
if
(
type
==
"hasMany"
)
{
baseDB
[
check
].
hasMany
(
baseDB
[
tableName
]);
mysqlModelMap
[
check
].
hasMany
(
mysqlModelMap
[
tableName
]);
}
baseDB
[
tableName
].
belongsTo
(
baseDB
[
check
]);
mysqlModelMap
[
tableName
].
belongsTo
(
mysqlModelMap
[
check
]);
}
});
}
...
...
@@ -43,4 +43,4 @@ export async function initMysqlModel() {
}
export
{
baseDB
};
\ No newline at end of file
export
{
mysqlModelMap
};
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment