|
|
@@ -6,7 +6,7 @@ module.exports = function(crowi) {
|
|
|
|
|
|
, USER_GROUP_PUBLIC_FIELDS = '_id image name createdAt'
|
|
|
|
|
|
- , PAGE_ITEMS = 50
|
|
|
+ , PAGE_ITEMS = 10
|
|
|
|
|
|
, userGroupSchema;
|
|
|
|
|
|
@@ -20,36 +20,36 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
|
// TBD: グループ画像の更新
|
|
|
- // userGroupSchema.methods.updateImage = function(image, callback) {
|
|
|
- // this.image = image;
|
|
|
- // this.save(function(err, userGroupData) {
|
|
|
- // return callback(err, userGroupData);
|
|
|
- // });
|
|
|
- // };
|
|
|
+ userGroupSchema.methods.updateImage = function(image, callback) {
|
|
|
+ this.image = image;
|
|
|
+ this.save(function(err, userGroupData) {
|
|
|
+ return callback(err, userGroupData);
|
|
|
+ });
|
|
|
+ };
|
|
|
|
|
|
// TBD: グループ画像の削除
|
|
|
- // userGroupSchema.methods.deleteImage = function(callback) {
|
|
|
- // return this.updateImage(null, callback);
|
|
|
- // };
|
|
|
+ userGroupSchema.methods.deleteImage = function(callback) {
|
|
|
+ return this.updateImage(null, callback);
|
|
|
+ };
|
|
|
|
|
|
- // グループ公開情報のフィルター
|
|
|
- userGroupSchema.statics.filterToPublicFields = function(userGroup) {
|
|
|
- debug('UserGroup is', typeof userGroup, userGroup);
|
|
|
- if (typeof userGroup !== 'object' || !userGroup._id) {
|
|
|
- return userGroup;
|
|
|
- }
|
|
|
-
|
|
|
- var filteredGroup = {};
|
|
|
- var fields = USER_GROUP_PUBLIC_FIELDS.split(' ');
|
|
|
- for (var i = 0; i < fields.length; i++) {
|
|
|
- var key = fields[i];
|
|
|
- if (userGroup[key]) {
|
|
|
- filteredGroup[key] = userGroup[key];
|
|
|
- }
|
|
|
- }
|
|
|
+ // // グループ公開情報のフィルター
|
|
|
+ // userGroupSchema.statics.filterToPublicFields = function(userGroup) {
|
|
|
+ // debug('UserGroup is', typeof userGroup, userGroup);
|
|
|
+ // if (typeof userGroup !== 'object' || !userGroup._id) {
|
|
|
+ // return userGroup;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // var filteredGroup = {};
|
|
|
+ // var fields = USER_GROUP_PUBLIC_FIELDS.split(' ');
|
|
|
+ // for (var i = 0; i < fields.length; i++) {
|
|
|
+ // var key = fields[i];
|
|
|
+ // if (userGroup[key]) {
|
|
|
+ // filteredGroup[key] = userGroup[key];
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
- return filteredGroup;
|
|
|
- };
|
|
|
+ // return filteredGroup;
|
|
|
+ // };
|
|
|
|
|
|
// TBD: グループ検索
|
|
|
// userGroupSchema.statics.findGroups = function(options, callback) {
|
|
|
@@ -70,16 +70,15 @@ module.exports = function(crowi) {
|
|
|
debug('NoErrorOccured');
|
|
|
|
|
|
var UserGroup = this;
|
|
|
- var option = option || {}
|
|
|
- , sort = option.sort || {createdAt: -1}
|
|
|
- , fields = option.fields || USER_GROUP_PUBLIC_FIELDS
|
|
|
- ;
|
|
|
+ // var option = option || {}
|
|
|
+ // , sort = option.sort || {createdAt: -1}
|
|
|
+ // , fields = option.fields || USER_GROUP_PUBLIC_FIELDS
|
|
|
+ // ;
|
|
|
|
|
|
+ console.log('');
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
UserGroup
|
|
|
.find()
|
|
|
- .select(fields)
|
|
|
- .sort(sort)
|
|
|
.exec(function (err, userGroupData) {
|
|
|
if (err) {
|
|
|
return reject(err);
|
|
|
@@ -117,8 +116,7 @@ module.exports = function(crowi) {
|
|
|
userGroupSchema.statics.findUserGroupsWithPagination = function(options, callback) {
|
|
|
var sort = options.sort || {name: 1, createdAt: 1};
|
|
|
|
|
|
- // return callback(err, null);
|
|
|
- this.paginate({ page: options.page || 1, limit: options.limit || PAGE_ITEMS }, function(err, result) {
|
|
|
+ this.paginate({}, { page: options.page || 1, limit: options.limit || PAGE_ITEMS }, function(err, result) {
|
|
|
if (err) {
|
|
|
debug('Error on pagination:', err);
|
|
|
return callback(err, null);
|
|
|
@@ -143,17 +141,17 @@ module.exports = function(crowi) {
|
|
|
// };
|
|
|
|
|
|
// TBD: 登録可能グループ名確認
|
|
|
- // userGroupSchema.statics.isRegisterableName = function(name, callback) {
|
|
|
- // var UserGroup = this;
|
|
|
- // var userGroupnameUsable = true;
|
|
|
+ userGroupSchema.statics.isRegisterableName = function(name, callback) {
|
|
|
+ var UserGroup = this;
|
|
|
+ var userGroupnameUsable = true;
|
|
|
|
|
|
- // this.findOne({name: name}, function (err, userGroupData) {
|
|
|
- // if (userGroupData) {
|
|
|
- // userGroupnameUsable = false;
|
|
|
- // }
|
|
|
- // return callback(userGroupnameUsable);
|
|
|
- // });
|
|
|
- // };
|
|
|
+ this.findOne({name: name}, function (err, userGroupData) {
|
|
|
+ if (userGroupData) {
|
|
|
+ userGroupnameUsable = false;
|
|
|
+ }
|
|
|
+ return callback(userGroupnameUsable);
|
|
|
+ });
|
|
|
+ };
|
|
|
|
|
|
// TBD: グループの完全削除
|
|
|
// userGroupSchema.statics.removeCompletelyById = function(id, callback) {
|
|
|
@@ -189,14 +187,14 @@ module.exports = function(crowi) {
|
|
|
};
|
|
|
|
|
|
// TBD: グループ画像パスの生成
|
|
|
- // userGroupSchema.statics.createGroupPictureFilePath = function(userGroup, name) {
|
|
|
- // var ext = '.' + name.match(/(.*)(?:\.([^.]+$))/)[2];
|
|
|
+ userGroupSchema.statics.createGroupPictureFilePath = function(userGroup, name) {
|
|
|
+ var ext = '.' + name.match(/(.*)(?:\.([^.]+$))/)[2];
|
|
|
|
|
|
- // return 'userGroup/' + userGroup._id + ext;
|
|
|
- // };
|
|
|
+ return 'userGroup/' + userGroup._id + ext;
|
|
|
+ };
|
|
|
|
|
|
|
|
|
- userGroupSchema.statics.USER_GROUP_PUBLIC_FIELDS = USER_GROUP_PUBLIC_FIELDS;
|
|
|
+ // userGroupSchema.statics.USER_GROUP_PUBLIC_FIELDS = USER_GROUP_PUBLIC_FIELDS;
|
|
|
userGroupSchema.statics.PAGE_ITEMS = PAGE_ITEMS;
|
|
|
|
|
|
return mongoose.model('UserGroup', userGroupSchema);
|