express-ext 0.4.14 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/access.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ function allow(access) {
4
+ var ao = access.origin
5
+ if (typeof ao === "string") {
6
+ return function (req, res, next) {
7
+ res.header("Access-Control-Allow-Origin", access.origin)
8
+ res.header("Access-Control-Allow-Credentials", access.credentials)
9
+ res.header("Access-Control-Allow-Methods", access.methods)
10
+ res.setHeader("Access-Control-Allow-Headers", access.headers)
11
+ next()
12
+ }
13
+ } else if (Array.isArray(ao) && ao.length > 0) {
14
+ return function (req, res, next) {
15
+ var origin = req.headers.origin
16
+ if (origin) {
17
+ if (ao.includes(origin)) {
18
+ res.setHeader("Access-Control-Allow-Origin", origin)
19
+ }
20
+ }
21
+ res.header("Access-Control-Allow-Credentials", access.credentials)
22
+ res.header("Access-Control-Allow-Methods", access.methods)
23
+ res.setHeader("Access-Control-Allow-Headers", access.headers)
24
+ next()
25
+ }
26
+ }
27
+ return function (req, res, next) {
28
+ res.header("Access-Control-Allow-Credentials", access.credentials)
29
+ res.header("Access-Control-Allow-Methods", access.methods)
30
+ res.setHeader("Access-Control-Allow-Headers", access.headers)
31
+ next()
32
+ }
33
+ }
34
+ exports.allow = allow
package/lib/index.js CHANGED
@@ -22,6 +22,7 @@ exports.Handler = LowCodeController_1.Controller
22
22
  var resources_1 = require("./resources")
23
23
  var SearchController_1 = require("./SearchController")
24
24
  exports.SearchHandler = SearchController_1.SearchController
25
+ __export(require("./access"))
25
26
  __export(require("./client"))
26
27
  __export(require("./edit"))
27
28
  __export(require("./GenericController"))
@@ -38,64 +39,30 @@ __export(require("./resources"))
38
39
  __export(require("./search"))
39
40
  __export(require("./SearchController"))
40
41
  __export(require("./view"))
41
- function allow(access) {
42
- var ao = access.origin
43
- if (typeof ao === "string") {
44
- return function (req, res, next) {
45
- res.header("Access-Control-Allow-Origin", access.origin)
46
- res.header("Access-Control-Allow-Credentials", access.credentials)
47
- res.header("Access-Control-Allow-Methods", access.methods)
48
- res.setHeader("Access-Control-Allow-Headers", access.headers)
49
- next()
50
- }
51
- } else if (Array.isArray(ao) && ao.length > 0) {
52
- return function (req, res, next) {
53
- var origin = req.headers.origin
54
- if (origin) {
55
- if (ao.includes(origin)) {
56
- res.setHeader("Access-Control-Allow-Origin", origin)
57
- }
58
- }
59
- res.header("Access-Control-Allow-Credentials", access.credentials)
60
- res.header("Access-Control-Allow-Methods", access.methods)
61
- res.setHeader("Access-Control-Allow-Headers", access.headers)
62
- next()
63
- }
64
- }
65
- return function (req, res, next) {
66
- res.header("Access-Control-Allow-Credentials", access.credentials)
67
- res.header("Access-Control-Allow-Methods", access.methods)
68
- res.setHeader("Access-Control-Allow-Headers", access.headers)
69
- next()
70
- }
71
- }
72
- exports.allow = allow
73
42
  var SavedController = (function () {
74
- function SavedController(log, service, item, id) {
43
+ function SavedController(savedService, log, id, userId) {
44
+ this.savedService = savedService
75
45
  this.log = log
76
- this.service = service
77
- this.item = item
46
+ this.userId = userId && userId.length > 0 ? userId : "userId"
78
47
  this.id = id && id.length > 0 ? id : "id"
79
48
  this.save = this.save.bind(this)
80
49
  this.remove = this.remove.bind(this)
81
- this.load = this.load.bind(this)
82
50
  }
83
51
  SavedController.prototype.save = function (req, res) {
84
52
  var _this = this
53
+ var userId = res.locals[this.userId]
85
54
  var id = req.params[this.id]
86
- var itemId = req.params[this.item]
87
55
  if (!id || id.length === 0) {
88
- res.status(400).end("'" + this.id + "' cannot be empty")
89
- return
56
+ return res.status(400).end("'" + this.id + "' cannot be empty")
90
57
  }
91
- if (!itemId || itemId.length === 0) {
92
- res.status(400).end("'" + this.item + "' cannot be empty")
93
- return
58
+ if (!userId || userId.length === 0) {
59
+ return res.status(400).end("'" + this.userId + "' cannot be empty")
94
60
  }
95
- this.service
96
- .save(id, itemId)
97
- .then(function (data) {
98
- res.status(200).json(data).end()
61
+ this.savedService
62
+ .save(userId, id)
63
+ .then(function (result) {
64
+ var status = result > 0 ? 200 : result === 0 ? 409 : 422
65
+ res.status(status).json(result).end()
99
66
  })
100
67
  .catch(function (err) {
101
68
  return http_1.handleError(err, res, _this.log)
@@ -103,36 +70,19 @@ var SavedController = (function () {
103
70
  }
104
71
  SavedController.prototype.remove = function (req, res) {
105
72
  var _this = this
73
+ var userId = res.locals[this.userId]
106
74
  var id = req.params[this.id]
107
- var itemId = req.params[this.item]
108
75
  if (!id || id.length === 0) {
109
- res.status(400).end("'" + this.id + "' cannot be empty")
110
- return
76
+ return res.status(400).end("'" + this.id + "' cannot be empty")
111
77
  }
112
- if (!itemId || itemId.length === 0) {
113
- res.status(400).end("'" + this.item + "' cannot be empty")
114
- return
78
+ if (!userId || userId.length === 0) {
79
+ return res.status(400).end("'" + this.userId + "' cannot be empty")
115
80
  }
116
- this.service
117
- .remove(id, itemId)
118
- .then(function (data) {
119
- res.status(200).json(data).end()
120
- })
121
- .catch(function (err) {
122
- return http_1.handleError(err, res, _this.log)
123
- })
124
- }
125
- SavedController.prototype.load = function (req, res) {
126
- var _this = this
127
- var id = req.params[this.id]
128
- if (!id || id.length === 0) {
129
- res.status(400).end("'" + this.id + "' cannot be empty")
130
- return
131
- }
132
- this.service
133
- .load(id)
134
- .then(function (data) {
135
- res.status(200).json(data).end()
81
+ this.savedService
82
+ .remove(userId, id)
83
+ .then(function (result) {
84
+ var status = result > 0 ? 200 : 410
85
+ res.status(status).json(result).end()
136
86
  })
137
87
  .catch(function (err) {
138
88
  return http_1.handleError(err, res, _this.log)
@@ -142,10 +92,10 @@ var SavedController = (function () {
142
92
  })()
143
93
  exports.SavedController = SavedController
144
94
  var FollowController = (function () {
145
- function FollowController(log, service, target, id) {
146
- this.log = log
95
+ function FollowController(service, log, id, userId) {
147
96
  this.service = service
148
- this.target = target
97
+ this.log = log
98
+ this.userId = userId && userId.length > 0 ? userId : "userId"
149
99
  this.id = id && id.length > 0 ? id : "id"
150
100
  this.follow = this.follow.bind(this)
151
101
  this.unfollow = this.unfollow.bind(this)
@@ -153,20 +103,19 @@ var FollowController = (function () {
153
103
  }
154
104
  FollowController.prototype.follow = function (req, res) {
155
105
  var _this = this
156
- var id = req.params.id
157
- var target = req.params.target
106
+ var userId = res.locals[this.userId]
107
+ var id = req.params[this.id]
158
108
  if (!id || id.length === 0) {
159
- res.status(400).end("'" + this.id + "' cannot be empty")
160
- return
109
+ return res.status(400).end("'" + this.id + "' cannot be empty")
161
110
  }
162
- if (!target || target.length === 0) {
163
- res.status(400).end("'" + this.target + "' cannot be empty")
164
- return
111
+ if (!userId || userId.length === 0) {
112
+ return res.status(400).end("'" + this.userId + "' cannot be empty")
165
113
  }
166
114
  this.service
167
- .follow(id, target)
168
- .then(function (count) {
169
- return res.status(200).json(count).end()
115
+ .follow(userId, id)
116
+ .then(function (result) {
117
+ var status = result > 0 ? 200 : 409
118
+ res.status(status).json(result).end()
170
119
  })
171
120
  .catch(function (err) {
172
121
  return http_1.handleError(err, res, _this.log)
@@ -174,20 +123,19 @@ var FollowController = (function () {
174
123
  }
175
124
  FollowController.prototype.unfollow = function (req, res) {
176
125
  var _this = this
177
- var id = req.params.id
178
- var target = req.params.target
126
+ var userId = res.locals[this.userId]
127
+ var id = req.params[this.id]
179
128
  if (!id || id.length === 0) {
180
- res.status(400).end("'" + this.id + "' cannot be empty")
181
- return
129
+ return res.status(400).end("'" + this.id + "' cannot be empty")
182
130
  }
183
- if (!target || target.length === 0) {
184
- res.status(400).end("'" + this.target + "' cannot be empty")
185
- return
131
+ if (!userId || userId.length === 0) {
132
+ return res.status(400).end("'" + this.userId + "' cannot be empty")
186
133
  }
187
134
  this.service
188
- .unfollow(id, target)
189
- .then(function (count) {
190
- return res.status(200).json(count).end()
135
+ .unfollow(userId, id)
136
+ .then(function (result) {
137
+ var status = result > 0 ? 200 : 410
138
+ res.status(status).json(result).end()
191
139
  })
192
140
  .catch(function (err) {
193
141
  return http_1.handleError(err, res, _this.log)
@@ -195,18 +143,16 @@ var FollowController = (function () {
195
143
  }
196
144
  FollowController.prototype.checkFollow = function (req, res) {
197
145
  var _this = this
198
- var id = req.params.id
199
- var target = req.params.target
146
+ var userId = res.locals[this.userId]
147
+ var id = req.params[this.id]
200
148
  if (!id || id.length === 0) {
201
- res.status(400).end("'" + this.id + "' cannot be empty")
202
- return
149
+ return res.status(400).end("'" + this.id + "' cannot be empty")
203
150
  }
204
- if (!target || target.length === 0) {
205
- res.status(400).end("'" + this.target + "' cannot be empty")
206
- return
151
+ if (!userId || userId.length === 0) {
152
+ return res.status(400).end("'" + this.userId + "' cannot be empty")
207
153
  }
208
154
  this.service
209
- .checkFollow(id, target)
155
+ .checkFollow(userId, id)
210
156
  .then(function (count) {
211
157
  return res.status(200).json(count).end()
212
158
  })
@@ -400,9 +346,10 @@ function escapeHTML(input) {
400
346
  })
401
347
  }
402
348
  exports.escapeHTML = escapeHTML
403
- function generateChip(value, text, noClose) {
349
+ function generateChip(value, text, noClose, hasStar) {
404
350
  var s = noClose ? "" : '<span class="close" onclick="removeChip(event)"></span>'
405
- return '<div class="chip" data-value="' + escapeHTML(value) + '">' + escapeHTML(text) + s + "</div>"
351
+ var t = hasStar ? '<i className="star highlight"></i>' : ""
352
+ return '<div class="chip" data-value="' + escapeHTML(value) + '">' + escapeHTML(text) + t + s + "</div>"
406
353
  }
407
354
  exports.generateChip = generateChip
408
355
  function generateTags(v, noClose) {
@@ -427,6 +374,17 @@ function generateChips(v, noClose) {
427
374
  .join("")
428
375
  }
429
376
  exports.generateChips = generateChips
377
+ function generateStarChips(v, value, text, star, noClose) {
378
+ return !v
379
+ ? ""
380
+ : "" +
381
+ v
382
+ .map(function (s) {
383
+ return generateChip(s[value], s[text], noClose, s[star] === true)
384
+ })
385
+ .join("")
386
+ }
387
+ exports.generateStarChips = generateStarChips
430
388
  var s = "string"
431
389
  var o = "object"
432
390
  function escape(obj) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-ext",
3
- "version": "0.4.14",
3
+ "version": "0.5.0",
4
4
  "description": "express-ext",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/access.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { NextFunction } from "express"
2
+ import { ParamsDictionary, Request, Response } from "express-serve-static-core"
3
+ import { ParsedQs } from "qs"
4
+
5
+ export interface AccessConfig {
6
+ origin?: string | string[]
7
+ credentials?: string | string[]
8
+ methods?: string | string[]
9
+ headers: number | string | ReadonlyArray<string>
10
+ }
11
+ export type AccessControlAllowConfig = AccessConfig
12
+ export function allow(
13
+ access: AccessConfig,
14
+ ): (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>, next: NextFunction) => void {
15
+ const ao = access.origin
16
+ if (typeof ao === "string") {
17
+ return (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>, next: NextFunction) => {
18
+ res.header("Access-Control-Allow-Origin", access.origin)
19
+ res.header("Access-Control-Allow-Credentials", access.credentials)
20
+ res.header("Access-Control-Allow-Methods", access.methods)
21
+ res.setHeader("Access-Control-Allow-Headers", access.headers)
22
+ next()
23
+ }
24
+ } else if (Array.isArray(ao) && ao.length > 0) {
25
+ return (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>, next: NextFunction) => {
26
+ const origin = req.headers.origin
27
+ if (origin) {
28
+ if (ao.includes(origin)) {
29
+ res.setHeader("Access-Control-Allow-Origin", origin)
30
+ }
31
+ }
32
+ res.header("Access-Control-Allow-Credentials", access.credentials)
33
+ res.header("Access-Control-Allow-Methods", access.methods)
34
+ res.setHeader("Access-Control-Allow-Headers", access.headers)
35
+ next()
36
+ }
37
+ }
38
+ return (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>, next: NextFunction) => {
39
+ res.header("Access-Control-Allow-Credentials", access.credentials)
40
+ res.header("Access-Control-Allow-Methods", access.methods)
41
+ res.setHeader("Access-Control-Allow-Headers", access.headers)
42
+ next()
43
+ }
44
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NextFunction, Request, Response } from "express"
1
+ import { Request, Response } from "express"
2
2
  import { GenericController } from "./GenericController"
3
3
  import { GenericSearchController } from "./GenericSearchController"
4
4
  import { HealthController } from "./HealthController"
@@ -23,6 +23,7 @@ export {
23
23
  SearchController as SearchHandler,
24
24
  }
25
25
 
26
+ export * from "./access"
26
27
  export * from "./client"
27
28
  export * from "./edit"
28
29
  export * from "./GenericController"
@@ -41,170 +42,115 @@ export * from "./search"
41
42
  export * from "./SearchController"
42
43
  export * from "./view"
43
44
 
44
- export interface AccessConfig {
45
- origin?: string | string[]
46
- credentials?: string | string[]
47
- methods?: string | string[]
48
- headers: number | string | ReadonlyArray<string>
45
+ export interface SavedService {
46
+ save(userId: string, id: string): Promise<number>
47
+ remove(userId: string, id: string): Promise<number>
49
48
  }
50
- export type AccessControlAllowConfig = AccessConfig
51
- export function allow(access: AccessConfig): (req: Request, res: Response, next: NextFunction) => void {
52
- const ao = access.origin
53
- if (typeof ao === "string") {
54
- return (req: Request, res: Response, next: NextFunction) => {
55
- res.header("Access-Control-Allow-Origin", access.origin)
56
- res.header("Access-Control-Allow-Credentials", access.credentials)
57
- res.header("Access-Control-Allow-Methods", access.methods)
58
- res.setHeader("Access-Control-Allow-Headers", access.headers)
59
- next()
60
- }
61
- } else if (Array.isArray(ao) && ao.length > 0) {
62
- return (req: Request, res: Response, next: NextFunction) => {
63
- const origin = req.headers.origin
64
- if (origin) {
65
- if (ao.includes(origin)) {
66
- res.setHeader("Access-Control-Allow-Origin", origin)
67
- }
68
- }
69
- res.header("Access-Control-Allow-Credentials", access.credentials)
70
- res.header("Access-Control-Allow-Methods", access.methods)
71
- res.setHeader("Access-Control-Allow-Headers", access.headers)
72
- next()
73
- }
74
- }
75
- return (req: Request, res: Response, next: NextFunction) => {
76
- res.header("Access-Control-Allow-Credentials", access.credentials)
77
- res.header("Access-Control-Allow-Methods", access.methods)
78
- res.setHeader("Access-Control-Allow-Headers", access.headers)
79
- next()
80
- }
81
- }
82
- export interface SavedService<T> {
83
- load(id: string): Promise<T[]>
84
- save(id: string, itemId: string): Promise<number>
85
- remove(id: string, itemId: string): Promise<number>
86
- }
87
- export class SavedController<T> {
88
- constructor(public log: (msg: string) => void, public service: SavedService<T>, public item: string, id?: string) {
49
+ export class SavedController {
50
+ constructor(protected savedService: SavedService, protected log: (msg: string) => void, id?: string, userId?: string) {
51
+ this.userId = userId && userId.length > 0 ? userId : "userId"
89
52
  this.id = id && id.length > 0 ? id : "id"
90
53
  this.save = this.save.bind(this)
91
54
  this.remove = this.remove.bind(this)
92
- this.load = this.load.bind(this)
93
55
  }
94
- id: string
56
+ protected userId: string
57
+ protected id: string
95
58
  save(req: Request, res: Response) {
59
+ const userId: string = res.locals[this.userId]
96
60
  const id = req.params[this.id]
97
- const itemId = req.params[this.item]
98
61
  if (!id || id.length === 0) {
99
- res.status(400).end(`'${this.id}' cannot be empty`)
100
- return
62
+ return res.status(400).end(`'${this.id}' cannot be empty`)
101
63
  }
102
- if (!itemId || itemId.length === 0) {
103
- res.status(400).end(`'${this.item}' cannot be empty`)
104
- return
64
+ if (!userId || userId.length === 0) {
65
+ return res.status(400).end(`'${this.userId}' cannot be empty`)
105
66
  }
106
- this.service
107
- .save(id, itemId)
108
- .then((data) => {
109
- res.status(200).json(data).end()
67
+ this.savedService
68
+ .save(userId, id)
69
+ .then((result) => {
70
+ const status = result > 0 ? 200 : result === 0 ? 409 : 422
71
+ res.status(status).json(result).end()
110
72
  })
111
73
  .catch((err) => handleError(err, res, this.log))
112
74
  }
113
75
  remove(req: Request, res: Response) {
76
+ const userId: string = res.locals[this.userId]
114
77
  const id = req.params[this.id]
115
- const itemId = req.params[this.item]
116
78
  if (!id || id.length === 0) {
117
- res.status(400).end(`'${this.id}' cannot be empty`)
118
- return
79
+ return res.status(400).end(`'${this.id}' cannot be empty`)
119
80
  }
120
- if (!itemId || itemId.length === 0) {
121
- res.status(400).end(`'${this.item}' cannot be empty`)
122
- return
123
- }
124
- this.service
125
- .remove(id, itemId)
126
- .then((data) => {
127
- res.status(200).json(data).end()
128
- })
129
- .catch((err) => handleError(err, res, this.log))
130
- }
131
- load(req: Request, res: Response) {
132
- const id = req.params[this.id]
133
- if (!id || id.length === 0) {
134
- res.status(400).end(`'${this.id}' cannot be empty`)
135
- return
81
+ if (!userId || userId.length === 0) {
82
+ return res.status(400).end(`'${this.userId}' cannot be empty`)
136
83
  }
137
- this.service
138
- .load(id)
139
- .then((data) => {
140
- res.status(200).json(data).end()
84
+ this.savedService
85
+ .remove(userId, id)
86
+ .then((result) => {
87
+ const status = result > 0 ? 200 : 410
88
+ res.status(status).json(result).end()
141
89
  })
142
90
  .catch((err) => handleError(err, res, this.log))
143
91
  }
144
92
  }
145
93
  export interface FollowService {
146
- follow(id: string, target: string): Promise<number | undefined>
94
+ follow(id: string, target: string): Promise<number>
147
95
  unfollow(id: string, target: string): Promise<number>
148
96
  checkFollow(id: string, target: string): Promise<number>
149
97
  }
150
98
  // tslint:disable-next-line:max-classes-per-file
151
99
  export class FollowController {
152
- constructor(public log: Log, public service: FollowService, public target: string, id: string) {
100
+ constructor(protected service: FollowService, protected log: Log, id?: string, userId?: string) {
101
+ this.userId = userId && userId.length > 0 ? userId : "userId"
153
102
  this.id = id && id.length > 0 ? id : "id"
154
103
  this.follow = this.follow.bind(this)
155
104
  this.unfollow = this.unfollow.bind(this)
156
105
  this.checkFollow = this.checkFollow.bind(this)
157
106
  }
158
- id: string
107
+ protected userId: string
108
+ protected id: string
159
109
  follow(req: Request, res: Response): void {
160
- const id = req.params.id
161
- const target = req.params.target
110
+ const userId: string = res.locals[this.userId]
111
+ const id = req.params[this.id]
162
112
  if (!id || id.length === 0) {
163
- res.status(400).end(`'${this.id}' cannot be empty`)
164
- return
113
+ return res.status(400).end(`'${this.id}' cannot be empty`)
165
114
  }
166
- if (!target || target.length === 0) {
167
- res.status(400).end(`'${this.target}' cannot be empty`)
168
- return
115
+ if (!userId || userId.length === 0) {
116
+ return res.status(400).end(`'${this.userId}' cannot be empty`)
169
117
  }
170
118
  this.service
171
- .follow(id, target)
172
- .then((count) => {
173
- return res.status(200).json(count).end()
119
+ .follow(userId, id)
120
+ .then((result) => {
121
+ const status = result > 0 ? 200 : 409
122
+ res.status(status).json(result).end()
174
123
  })
175
124
  .catch((err) => handleError(err, res, this.log))
176
125
  }
177
126
  unfollow(req: Request, res: Response): void {
178
- const id = req.params.id
179
- const target = req.params.target
127
+ const userId: string = res.locals[this.userId]
128
+ const id = req.params[this.id]
180
129
  if (!id || id.length === 0) {
181
- res.status(400).end(`'${this.id}' cannot be empty`)
182
- return
130
+ return res.status(400).end(`'${this.id}' cannot be empty`)
183
131
  }
184
- if (!target || target.length === 0) {
185
- res.status(400).end(`'${this.target}' cannot be empty`)
186
- return
132
+ if (!userId || userId.length === 0) {
133
+ return res.status(400).end(`'${this.userId}' cannot be empty`)
187
134
  }
188
135
  this.service
189
- .unfollow(id, target)
190
- .then((count) => {
191
- return res.status(200).json(count).end()
136
+ .unfollow(userId, id)
137
+ .then((result) => {
138
+ const status = result > 0 ? 200 : 410
139
+ res.status(status).json(result).end()
192
140
  })
193
141
  .catch((err) => handleError(err, res, this.log))
194
142
  }
195
143
  checkFollow(req: Request, res: Response): void {
196
- const id = req.params.id
197
- const target = req.params.target
144
+ const userId: string = res.locals[this.userId]
145
+ const id = req.params[this.id]
198
146
  if (!id || id.length === 0) {
199
- res.status(400).end(`'${this.id}' cannot be empty`)
200
- return
147
+ return res.status(400).end(`'${this.id}' cannot be empty`)
201
148
  }
202
- if (!target || target.length === 0) {
203
- res.status(400).end(`'${this.target}' cannot be empty`)
204
- return
149
+ if (!userId || userId.length === 0) {
150
+ return res.status(400).end(`'${this.userId}' cannot be empty`)
205
151
  }
206
152
  this.service
207
- .checkFollow(id, target)
153
+ .checkFollow(userId, id)
208
154
  .then((count) => {
209
155
  return res.status(200).json(count).end()
210
156
  })
@@ -384,9 +330,10 @@ export function escapeHTML(input: string): string {
384
330
  return map[char]
385
331
  })
386
332
  }
387
- export function generateChip(value: string, text: string, noClose?: boolean): string {
333
+ export function generateChip(value: string, text: string, noClose?: boolean, hasStar?: boolean): string {
388
334
  const s = noClose ? "" : `<span class="close" onclick="removeChip(event)"></span>`
389
- return `<div class="chip" data-value="${escapeHTML(value)}">${escapeHTML(text)}${s}</div>`
335
+ const t = hasStar ? `<i className="star highlight"></i>` : ""
336
+ return `<div class="chip" data-value="${escapeHTML(value)}">${escapeHTML(text)}${t}${s}</div>`
390
337
  }
391
338
  export function generateTags(v?: string[] | null, noClose?: boolean): string {
392
339
  return !v ? "" : `${v.map((s) => generateChip(s, s, noClose)).join("")}`
@@ -398,6 +345,9 @@ export interface Item {
398
345
  export function generateChips(v?: Item[] | null, noClose?: boolean): string {
399
346
  return !v ? "" : `${v.map((s) => generateChip(s.value, s.text, noClose)).join("")}`
400
347
  }
348
+ export function generateStarChips(v: any[] | null | undefined, value: string, text: string, star: string, noClose?: boolean): string {
349
+ return !v ? "" : `${v.map((s) => generateChip(s[value], s[text], noClose, s[star] === true)).join("")}`
350
+ }
401
351
 
402
352
  const s = "string"
403
353
  const o = "object"