@shun-js/user 0.4.3 → 0.4.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shun-js/user",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "user",
5
5
  "keywords": [
6
6
  "shun.js",
@@ -34,5 +34,5 @@
34
34
  "access": "public",
35
35
  "registry": "https://registry.npmjs.org/"
36
36
  },
37
- "gitHead": "03c6078d94915e4535031dbd04e507b21b6aa517"
37
+ "gitHead": "2defaa9089506eb53bcae4d248d281b98465e6ad"
38
38
  }
@@ -2,18 +2,18 @@
2
2
  const sql = require('../sql/UserInfoSQL.js');
3
3
 
4
4
  /**
5
- * getUserInfoById
5
+ * isUserInfoExists
6
6
  * @param {*} req
7
7
  * @param {*} res
8
8
  * @param {*} id
9
9
  * @returns
10
10
  */
11
- exports.getUserInfoById = async (req, res, id) => {
12
- const methodName = 'getUserInfoById';
11
+ exports.isUserInfoExists = async (req, res, id) => {
12
+ const methodName = 'isUserInfoExists';
13
13
 
14
14
  // get user item
15
15
  try {
16
- return await req.db.query(sql.getUserInfoById, [id]);
16
+ return await req.db.query(sql.isUserInfoExists, [id]);
17
17
  } catch (error) {
18
18
  const msg = '获取用户信息失败!';
19
19
  req.logger.error(methodName, msg, error.name, error.message);
@@ -46,3 +46,31 @@ exports.addUserInfo = async (req, res, userItemId, githubUserinfo) => {
46
46
  res.jsonFail(msg);
47
47
  }
48
48
  };
49
+
50
+ /**
51
+ * getUserInfoById
52
+ * @param {*} req
53
+ * @param {*} res
54
+ * @param {*} id
55
+ * @returns
56
+ */
57
+ exports.getUserInfoById = async (req, res, id) => {
58
+ const methodName = 'getUserInfoById';
59
+
60
+ // get user item
61
+ try {
62
+ const getUserInfoByIdRes = await req.db.query(sql.getUserInfoById, [id]);
63
+ if (getUserInfoByIdRes.length !== 1) {
64
+ const msg = '用户信息长度非1!';
65
+ req.logger.error(methodName, msg);
66
+ res.jsonFail(msg);
67
+ return;
68
+ }
69
+
70
+ return getUserInfoByIdRes[0];
71
+ } catch (error) {
72
+ const msg = '获取用户信息失败!';
73
+ req.logger.error(methodName, msg, error.name, error.message);
74
+ res.jsonFail(msg);
75
+ }
76
+ };
@@ -1,5 +1,5 @@
1
1
  // model
2
- const { getUserInfoById, addUserInfo } = require('../model/UserInfoModel.js');
2
+ const { addUserInfo, isUserInfoExists } = require('../model/UserInfoModel.js');
3
3
 
4
4
  // github
5
5
  const { getGithubUserinfo } = require('../util/github.js');
@@ -42,9 +42,9 @@ exports.userGithub = async (req, res) => {
42
42
  req.logger.info(methodName, 'github login or reg ok');
43
43
 
44
44
  // user info
45
- const getUserInfoByIdRes = await getUserInfoById(req, res, userItem.id);
46
- if (!getUserInfoByIdRes) return;
47
- if (getUserInfoByIdRes.length === 0) {
45
+ const isUserInfoExistsRes = await isUserInfoExists(req, res, userItem.id);
46
+ if (!isUserInfoExistsRes) return;
47
+ if (isUserInfoExistsRes.length === 0) {
48
48
  const addUserInfoRes = await addUserInfo(req, res, userItem.id, githubUserinfo);
49
49
  if (!addUserInfoRes) return;
50
50
  }
@@ -1,12 +1,13 @@
1
- exports.getUserInfoById = `
1
+ exports.isUserInfoExists = `
2
2
  select
3
- *
3
+ 1
4
4
  from
5
5
  t_user_info
6
6
  where
7
7
  user_item_id=?
8
8
  and
9
9
  del_tag='0'
10
+ LIMIT 1
10
11
  `;
11
12
 
12
13
  exports.addUserInfo = `
@@ -15,3 +16,15 @@ insert into
15
16
  values
16
17
  (null, ?, ?, ?, ?, now(), '0')
17
18
  `;
19
+
20
+ exports.getUserInfoById = `
21
+ select
22
+ *
23
+ from
24
+ t_user_info
25
+ where
26
+ user_item_id=?
27
+ and
28
+ del_tag='0'
29
+ LIMIT 1
30
+ `;