Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
utools_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
wuhao
utools_backend
Commits
6346bb2c
Commit
6346bb2c
authored
Feb 20, 2023
by
wuhao
🎯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asder
parent
9c090f1e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
231 additions
and
2 deletions
+231
-2
item.js
app/controller/item.js
+1
-0
tag.js
app/controller/tag.js
+86
-0
item.js
app/model/item.js
+7
-1
tag.js
app/model/tag.js
+64
-0
router.js
app/router.js
+3
-0
tag.js
app/service/tag.js
+47
-0
20230216022317-init-items.js
database/migrations/20230216022317-init-items.js
+2
-1
20230220011850-init-tags.js
database/migrations/20230220011850-init-tags.js
+21
-0
No files found.
app/controller/item.js
View file @
6346bb2c
...
@@ -41,6 +41,7 @@ class ItemController extends Controller {
...
@@ -41,6 +41,7 @@ class ItemController extends Controller {
return
;
return
;
}
}
const
item
=
await
ctx
.
model
.
Item
.
create
(
ctx
.
request
.
body
);
const
item
=
await
ctx
.
model
.
Item
.
create
(
ctx
.
request
.
body
);
// const tags = await ctx.model.service.tags
this
.
success
(
item
);
this
.
success
(
item
);
}
}
...
...
app/controller/tag.js
0 → 100755
View file @
6346bb2c
'use strict'
;
const
Controller
=
require
(
'../core/base_controller'
);
function
toInt
(
str
)
{
if
(
typeof
str
===
'number'
)
return
str
;
if
(
!
str
)
return
str
;
return
parseInt
(
str
,
10
)
||
0
;
}
class
TagController
extends
Controller
{
async
mutitag
()
{
const
ctx
=
this
.
ctx
;
const
updates
=
await
ctx
.
service
.
tag
.
mutiupdate
(
ctx
.
request
.
body
?.
tags
??
[]
);
this
.
success
(
updates
);
}
async
index
()
{
const
ctx
=
this
.
ctx
;
const
query
=
{
project_id
:
ctx
.
query
.
project_id
,
};
const
result
=
await
ctx
.
model
.
Tag
.
findAll
({
where
:
query
});
this
.
success
(
result
);
}
async
show
()
{
const
ctx
=
this
.
ctx
;
const
result
=
await
ctx
.
model
.
Tag
.
findByPk
(
toInt
(
ctx
.
params
.
id
));
this
.
success
(
result
);
}
async
create
()
{
const
ctx
=
this
.
ctx
;
console
.
log
(
ctx
.
request
.
body
);
if
(
!
ctx
.
request
.
body
.
tag_name
||
!
ctx
.
request
.
body
.
project_id
)
{
this
.
fail
(
'请完善必填项!'
);
return
;
}
const
tag
=
await
ctx
.
model
.
Tag
.
create
(
ctx
.
request
.
body
);
this
.
success
(
tag
);
}
async
update
()
{
const
ctx
=
this
.
ctx
;
const
id
=
toInt
(
ctx
.
params
.
id
);
const
tag
=
await
ctx
.
model
.
Tag
.
findByPk
(
id
);
if
(
!
tag
)
{
ctx
.
status
=
404
;
ctx
.
body
=
{
code
:
1
,
success
:
false
,
msg
:
'库里没有该条数据'
,
};
return
;
}
await
tag
.
update
(
ctx
.
request
.
body
);
this
.
success
(
tag
);
}
async
destroy
()
{
const
ctx
=
this
.
ctx
;
const
id
=
toInt
(
ctx
.
params
.
id
);
const
tag
=
await
ctx
.
model
.
Tag
.
findByPk
(
id
);
if
(
!
tag
)
{
ctx
.
status
=
404
;
ctx
.
body
=
{
code
:
1
,
success
:
false
,
msg
:
'库里没有该条数据'
,
};
return
;
}
await
tag
.
destroy
();
this
.
success
({
data
:
'已删除'
,
});
}
}
module
.
exports
=
TagController
;
app/model/item.js
View file @
6346bb2c
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
'use strict'
;
'use strict'
;
module
.
exports
=
app
=>
{
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
ENUM
,
DATE
,
TEXT
}
=
app
.
Sequelize
;
const
{
STRING
,
INTEGER
,
ENUM
,
DATE
,
TEXT
,
JSON
}
=
app
.
Sequelize
;
const
Item
=
app
.
model
.
define
(
const
Item
=
app
.
model
.
define
(
'item'
,
'item'
,
...
@@ -51,6 +51,12 @@ module.exports = app => {
...
@@ -51,6 +51,12 @@ module.exports = app => {
comment
:
'冗余字段'
,
comment
:
'冗余字段'
,
unique
:
true
,
unique
:
true
,
},
},
tags
:
{
type
:
JSON
,
allowNull
:
true
,
comment
:
'标签'
,
unique
:
true
,
},
sort
:
{
sort
:
{
type
:
INTEGER
,
type
:
INTEGER
,
allowNull
:
true
,
allowNull
:
true
,
...
...
app/model/tag.js
0 → 100755
View file @
6346bb2c
/* eslint-disable no-unused-vars */
'use strict'
;
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
ENUM
,
DATE
,
TEXT
}
=
app
.
Sequelize
;
const
Tag
=
app
.
model
.
define
(
'tag'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
project_id
:
{
type
:
INTEGER
,
allowNull
:
true
,
comment
:
'所属项目'
,
unique
:
true
,
},
mission_id
:
{
type
:
INTEGER
,
allowNull
:
true
,
comment
:
'所属任务'
,
unique
:
true
,
},
tag_name
:
{
type
:
STRING
(
255
),
allowNull
:
true
,
comment
:
'标签名称'
,
unique
:
true
,
},
other
:
{
type
:
STRING
(
255
),
allowNull
:
true
,
comment
:
'冗余字段'
,
unique
:
true
,
},
color
:
{
type
:
STRING
(
255
),
allowNull
:
true
,
comment
:
'颜色'
,
unique
:
true
,
},
created_at
:
DATE
,
updated_at
:
DATE
,
},
{
timestamps
:
true
,
createdAt
:
'created_at'
,
updatedAt
:
'updated_at'
,
}
);
return
Tag
;
};
// freezeTableName: true, 使用自定义表名
// // 实例对应的表名
// tableName: 'user',
// // 如果需要sequelize帮你维护createdAt,updatedAt和deletedAt必须先启用timestamps功能
// // 将createdAt对应到数据库的created_at字段
// createdAt: 'created_at',
// // 将updatedAt对应到数据库的updated_at字段
// updatedAt: 'updated_at',
// //And deletedAt to be called destroyTime (remember to enable paranoid for this to work)
// deletedAt: false, //'deleted_at',
// //删除数据时不删除数据,而是更新deleteAt字段 如果需要设置为true,则上面的deleteAt字段不能为false,也就是说必须启用
// paranoid: false
app/router.js
View file @
6346bb2c
...
@@ -17,5 +17,8 @@ module.exports = app => {
...
@@ -17,5 +17,8 @@ module.exports = app => {
router
.
resources
(
'org'
,
'/webtool/v1/org'
,
jwtErr
,
controller
.
org
);
router
.
resources
(
'org'
,
'/webtool/v1/org'
,
jwtErr
,
controller
.
org
);
router
.
resources
(
'step'
,
'/webtool/v1/step'
,
jwtErr
,
controller
.
step
);
router
.
resources
(
'step'
,
'/webtool/v1/step'
,
jwtErr
,
controller
.
step
);
router
.
resources
(
'item'
,
'/webtool/v1/item'
,
jwtErr
,
controller
.
item
);
router
.
resources
(
'item'
,
'/webtool/v1/item'
,
jwtErr
,
controller
.
item
);
router
.
resources
(
'tag'
,
'/webtool/v1/tag'
,
controller
.
tag
);
router
.
post
(
'/webtool/v1/mutisort'
,
jwtErr
,
controller
.
item
.
mutisort
);
// 绑定用户组织
router
.
post
(
'/webtool/v1/mutisort'
,
jwtErr
,
controller
.
item
.
mutisort
);
// 绑定用户组织
router
.
post
(
'/webtool/v1/mutitag'
,
jwtErr
,
controller
.
tag
.
mutitag
);
// 绑定用户组织
};
};
app/service/tag.js
0 → 100755
View file @
6346bb2c
// app/service/user.js
const
Service
=
require
(
'egg'
).
Service
;
class
TagService
extends
Service
{
async
mutiupdate
(
tagarr
)
{
const
{
ctx
,
app
}
=
this
;
const
{
Op
}
=
app
.
Sequelize
;
let
tag
;
try
{
await
ctx
.
model
.
Tag
.
destroy
({
where
:
{
project_id
:
Array
.
from
(
new
Set
(
tagarr
.
map
(
it
=>
it
.
project_id
))),
// 所有名字为 John 的用户将被删除
},
});
tag
=
await
ctx
.
model
.
Tag
.
bulkCreate
(
tagarr
,
{
updateOnDuplicate
:
[
'project_id'
,
'tag_name'
],
});
}
catch
(
error
)
{
tag
=
error
;
}
return
tag
;
}
async
getbyproject_id
(
project_id
,
status
)
{
const
{
ctx
}
=
this
;
const
where
=
status
==
'-1'
?
{
project_id
,
}
:
{
project_id
,
status
,
};
let
tag
;
try
{
tag
=
await
ctx
.
model
.
Tag
.
findAll
({
where
,
});
}
catch
(
error
)
{
tag
=
error
;
}
return
tag
;
}
}
module
.
exports
=
TagService
;
database/migrations/20230216022317-init-items.js
View file @
6346bb2c
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
module
.
exports
=
{
module
.
exports
=
{
async
up
(
queryInterface
,
Sequelize
)
{
async
up
(
queryInterface
,
Sequelize
)
{
const
{
INTEGER
,
STRING
,
DATE
,
ENUM
,
TEXT
}
=
Sequelize
;
const
{
INTEGER
,
STRING
,
DATE
,
ENUM
,
TEXT
,
JSON
}
=
Sequelize
;
await
queryInterface
.
createTable
(
'items'
,
{
await
queryInterface
.
createTable
(
'items'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
project_id
:
INTEGER
,
project_id
:
INTEGER
,
...
@@ -11,6 +11,7 @@ module.exports = {
...
@@ -11,6 +11,7 @@ module.exports = {
status
:
ENUM
(
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
),
status
:
ENUM
(
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
),
deadline
:
DATE
,
deadline
:
DATE
,
other
:
STRING
(
255
),
other
:
STRING
(
255
),
tags
:
JSON
,
remark
:
TEXT
,
remark
:
TEXT
,
userid
:
INTEGER
,
userid
:
INTEGER
,
sort
:
INTEGER
,
sort
:
INTEGER
,
...
...
database/migrations/20230220011850-init-tags.js
0 → 100644
View file @
6346bb2c
'use strict'
;
module
.
exports
=
{
async
up
(
queryInterface
,
Sequelize
)
{
const
{
INTEGER
,
STRING
,
DATE
}
=
Sequelize
;
await
queryInterface
.
createTable
(
'tags'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
project_id
:
INTEGER
,
mission_id
:
INTEGER
,
tag_name
:
STRING
(
255
),
other
:
STRING
(
255
),
color
:
STRING
(
255
),
created_at
:
DATE
,
updated_at
:
DATE
,
});
},
async
down
(
queryInterface
)
{
await
queryInterface
.
dropTable
(
'tags'
);
},
};
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