明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jt_backend
Project
Project
Details
Activity
Releases
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
zengfanpei
jt_backend
Commits
00784b27
Commit
00784b27
authored
Nov 19, 2025
by
zhangqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加资源库路由
parent
0afa8810
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
175 additions
and
31 deletions
+175
-31
resourceController.js
controller/resourceController.js
+143
-7
userController.js
controller/userController.js
+22
-21
request.js
middleware/request.js
+1
-1
resourceRouter.js
router/resourceRouter.js
+9
-2
No files found.
controller/resourceController.js
View file @
00784b27
const
errorMessage
=
require
(
"../utils/errorMessage"
);
const
errorMessage
=
require
(
"../utils/errorMessage"
);
const
userModule
=
require
(
'../module/userModul
e'
);
const
{
Op
}
=
require
(
'sequeliz
e'
);
async
function
createRole
(
req
,
res
,
next
)
{
try
{
/**
////
* 资源库controller
}
catch
(
error
)
{
*/
next
(
error
);
async
function
createResource
(
req
,
res
,
next
)
{
try
{
const
body
=
req
.
body
;
const
ret
=
await
DB
.
Resources
.
create
(
body
);
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
};
async
function
updateResource
(
req
,
res
,
next
)
{
try
{
const
body
=
req
.
body
;
if
(
!
body
.
id
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
)
}
}
const
ret
=
await
DB
.
Resources
.
update
(
body
,
{
where
:
{
id
:
body
.
id
}
});
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
async
function
deleteResource
(
req
,
res
,
next
)
{
try
{
if
(
!
req
.
body
.
id
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
const
ret
=
await
DB
.
Resources
.
update
({
del
:
1
},
{
where
:
{
id
:
req
.
body
.
id
}
});
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
}
async
function
listResource
(
req
,
res
,
next
)
{
try
{
let
search
=
{
where
:
{
del
:
0
}
};
let
page
=
req
.
body
.
page
||
1
;
let
limit
=
req
.
body
.
pageSize
||
10
;
//翻页
let
offset
=
(
page
-
1
)
*
limit
;
if
(
req
.
body
.
name
)
{
search
.
where
=
{
[
Op
.
or
]:
[
//根据名字模糊搜索
{
name
:
{
[
Op
.
like
]:
`%
${
req
.
body
.
name
}
%`
}
}
],
del
:
0
,
}
}
search
.
limit
=
limit
;
search
.
offset
=
offset
;
//指定显示字段,空数组会报错
search
.
attributes
=
req
.
body
.
attributes
||
null
;
let
ret
=
await
DB
.
Resources
.
findAndCountAll
(
search
);
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
};
/**
* 资源库字段controller
*/
async
function
createResourceInfo
(
req
,
res
,
next
)
{
try
{
const
body
=
req
.
body
;
if
(
!
body
.
resourceId
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
)
}
const
resource
=
await
DB
.
Resources
.
findOne
({
where
:
{
id
:
body
.
resourceId
}
});
if
(
!
resource
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
)
}
const
ret
=
await
DB
.
ResourcesInfo
.
create
(
body
);
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
};
async
function
updateResourceInfo
(
req
,
res
,
next
)
{
try
{
const
body
=
req
.
body
;
if
(
!
body
.
id
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
)
}
const
ret
=
await
DB
.
ResourcesInfo
.
update
(
body
,
{
where
:
{
id
:
body
.
id
}
});
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
async
function
deleteResourceInfo
(
req
,
res
,
next
)
{
try
{
if
(
!
req
.
body
.
id
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
const
ret
=
await
DB
.
ResourcesInfo
.
update
({
del
:
1
},
{
where
:
{
id
:
req
.
body
.
id
}
});
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
async
function
listResourceInfo
(
req
,
res
,
next
)
{
try
{
let
search
=
{
where
:
{
del
:
0
}
};
let
page
=
req
.
body
.
page
||
1
;
let
limit
=
req
.
body
.
pageSize
||
10
;
//翻页
let
offset
=
(
page
-
1
)
*
limit
;
if
(
req
.
body
.
name
)
{
search
.
where
=
{
[
Op
.
or
]:
[
//根据value值模糊搜索
{
value
:
{
[
Op
.
like
]:
`%
${
req
.
body
.
name
}
%`
}
}
],
del
:
0
,
}
}
search
.
limit
=
limit
;
search
.
offset
=
offset
;
//指定显示字段,空数组会报错
search
.
attributes
=
req
.
body
.
attributes
||
null
;
let
ret
=
await
DB
.
ResourcesInfo
.
findAndCountAll
(
search
);
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
};
module
.
exports
=
{
module
.
exports
=
{
createResource
,
updateResource
,
deleteResource
,
listResource
,
createResourceInfo
,
updateResourceInfo
,
deleteResourceInfo
,
listResourceInfo
}
}
\ No newline at end of file
controller/userController.js
View file @
00784b27
...
@@ -31,28 +31,29 @@ async function login(req, res, next) {
...
@@ -31,28 +31,29 @@ async function login(req, res, next) {
const
{
mobile
,
password
}
=
req
.
body
;
const
{
mobile
,
password
}
=
req
.
body
;
let
user
=
await
DB
.
User
.
findOne
({
let
user
=
await
DB
.
User
.
findOne
({
where
:
{
mobile
,
del
:
0
,
enable
:
0
},
where
:
{
mobile
,
del
:
0
,
enable
:
0
},
include
:
[{
//
include: [{
model
:
DB
.
Role
,
//
model: DB.Role,
as
:
'roles'
,
//
as: 'roles',
where
:
{
del
:
0
},
//
where: { del: 0 },
attributes
:
[
"id"
,
"name"
],
//
attributes: ["id", "name"],
through
:
{
attributes
:
[]
},
//
through: { attributes: [] },
include
:
[{
//
include: [{
model
:
DB
.
Menu
,
//
model: DB.Menu,
as
:
'menus'
,
//
as: 'menus',
// where: { del: 0 },
//
// where: { del: 0 },
// attributes: ['id', 'name', 'parentId'],
//
// attributes: ['id', 'name', 'parentId'],
through
:
{
attributes
:
[]
},
//
through: { attributes: [] },
}]
//
}]
},
{
//
}, {
model
:
DB
.
Depart
,
//
model: DB.Depart,
as
:
'departs'
,
//
as: 'departs',
where
:
{
del
:
0
},
//
where: { del: 0 },
attributes
:
[
"id"
,
"name"
],
//
attributes: ["id", "name"],
through
:
{
attributes
:
[]
},
//
through: { attributes: [] },
}
//
}
]
//
]
});
});
// console.log('this is user login', user)
user
=
user
.
toJSON
();
user
=
user
.
toJSON
();
if
(
!
user
)
{
if
(
!
user
)
{
return
res
.
sendError
(
errorMessage
.
loginError
);
return
res
.
sendError
(
errorMessage
.
loginError
);
...
...
middleware/request.js
View file @
00784b27
...
@@ -13,7 +13,7 @@ module.exports = async (req, res, next) => {
...
@@ -13,7 +13,7 @@ module.exports = async (req, res, next) => {
}
}
req
.
headers
.
authorization
=
req
.
headers
.
authorization
||
req
.
headers
.
Authorization
;
req
.
headers
.
authorization
=
req
.
headers
.
authorization
||
req
.
headers
.
Authorization
;
const
userStr
=
await
ioRedis
.
get
(
`token:
${
req
.
headers
.
authorization
}
`
);
const
userStr
=
await
ioRedis
.
get
(
`token:
${
req
.
headers
.
authorization
}
`
);
//
console.log(userStr)
console
.
log
(
userStr
)
if
(
userStr
)
{
if
(
userStr
)
{
try
{
try
{
req
.
user
=
JSON
.
parse
(
userStr
);
req
.
user
=
JSON
.
parse
(
userStr
);
...
...
router/resourceRouter.js
View file @
00784b27
const
express
=
require
(
'express'
);
const
express
=
require
(
'express'
);
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
const
resourceController
=
require
(
'../controller/resourceController'
);
const
resourceController
=
require
(
'../controller/resourceController'
);
/**
/**
...
@@ -10,9 +8,18 @@ const resourceController = require('../controller/resourceController');
...
@@ -10,9 +8,18 @@ const resourceController = require('../controller/resourceController');
*/
*/
// router.post('/resource', resourceController.createResource);
// router.post('/resource', resourceController.createResource);
router
.
post
(
'/createResource'
,
resourceController
.
createResource
);
router
.
post
(
'/deleteResource'
,
resourceController
.
deleteResource
);
router
.
post
(
'/updateResource'
,
resourceController
.
updateResource
);
router
.
post
(
'/listResource'
,
resourceController
.
listResource
);
// router.post('/getProjectFields', projectController.getProjectFields);
/**
/**
* 资源库字段详情
* 资源库字段详情
*/
*/
// router.post('/resourceInfo', resourceController.createResourceInfo);
// router.post('/resourceInfo', resourceController.createResourceInfo);
router
.
post
(
'/createResourceInfo'
,
resourceController
.
createResourceInfo
);
router
.
post
(
'/deleteResourceInfo'
,
resourceController
.
deleteResourceInfo
);
router
.
post
(
'/updateResourceInfo'
,
resourceController
.
updateResourceInfo
);
router
.
post
(
'/listResourceInfo'
,
resourceController
.
listResourceInfo
);
module
.
exports
=
router
;
module
.
exports
=
router
;
\ 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