Explorar el Código

Merge pull request #3951 from weseek/feat/GW-6472-create-new-schema

Feat/gw 6472 create new schema
Shun Miyazawa hace 4 años
padre
commit
cf26f015ab
Se han modificado 2 ficheros con 18 adiciones y 0 borrados
  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 },
     createdAt: { type: Date, default: Date.now },
     lastLoginAt: { type: Date },
     lastLoginAt: { type: Date },
     admin: { type: Boolean, default: 0, index: true },
     admin: { type: Boolean, default: 0, index: true },
+    isInvitationEmailSended: { type: Boolean, default: false },
   }, {
   }, {
     toObject: {
     toObject: {
       transform: (doc, ret, opt) => {
       transform: (doc, ret, opt) => {
@@ -682,6 +683,21 @@ module.exports = function(crowi) {
     return username;
     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 {
   class UserUpperLimitException {
 
 
     constructor() {
     constructor() {

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

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