Просмотр исходного кода

Merge branch 'feat/mark-the-user' into feat/GW-6473-6497-mark-the-user

Shun Miyazawa 4 лет назад
Родитель
Сommit
e0d172df25
2 измененных файлов с 18 добавлено и 0 удалено
  1. 16 0
      src/server/models/user.js
  2. 2 0
      src/server/routes/apiv3/users.js

+ 16 - 0
src/server/models/user.js

@@ -63,6 +63,7 @@ module.exports = function(crowi) {
     createdAt: { type: Date, default: Date.now },
     lastLoginAt: { type: Date },
     admin: { type: Boolean, default: 0, index: true },
+    isInvitationEmailSended: { type: Boolean, default: false },
   }, {
     toObject: {
       transform: (doc, ret, opt) => {
@@ -682,6 +683,21 @@ module.exports = function(crowi) {
     return username;
   };
 
+  userSchema.statics.updateIsInvitationEmailSended = async function(id) {
+    const user = await this.findById(id);
+
+    if (user == null) {
+      throw new Error('User not found');
+    }
+
+    if (user.status !== 5) {
+      throw new Error('The status of the user is not "invited"');
+    }
+
+    user.isInvitationEmailSended = true;
+    user.save();
+  };
+
   class UserUpperLimitException {
 
     constructor() {

+ 2 - 0
src/server/routes/apiv3/users.js

@@ -125,6 +125,8 @@ module.exports = (crowi) => {
 
     for (const user of userList) {
       try {
+        // eslint-disable-next-line no-await-in-loop
+        await User.updateIsInvitationEmailSended(user.user.id);
         // eslint-disable-next-line no-await-in-loop
         await mailService.send({
           to: user.email,