mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
Deprecate API v2 (#7761)
* deprecate api-v2 * remove v2 test helpers * remove unused string
This commit is contained in:
@@ -7,17 +7,17 @@ import shared from '../../../common';
|
||||
import _ from 'lodash';
|
||||
import { model as Challenge} from './challenge';
|
||||
import validator from 'validator';
|
||||
import { removeFromArray } from '../libs/api-v3/collectionManipulators';
|
||||
import { removeFromArray } from '../libs/collectionManipulators';
|
||||
import {
|
||||
InternalServerError,
|
||||
BadRequest,
|
||||
} from '../libs/api-v3/errors';
|
||||
import baseModel from '../libs/api-v3/baseModel';
|
||||
import { sendTxn as sendTxnEmail } from '../libs/api-v3/email';
|
||||
} from '../libs/errors';
|
||||
import baseModel from '../libs/baseModel';
|
||||
import { sendTxn as sendTxnEmail } from '../libs/email';
|
||||
import Bluebird from 'bluebird';
|
||||
import nconf from 'nconf';
|
||||
import sendPushNotification from '../libs/api-v3/pushNotifications';
|
||||
import pusher from '../libs/api-v3/pusher';
|
||||
import sendPushNotification from '../libs/pushNotifications';
|
||||
import pusher from '../libs/pusher';
|
||||
|
||||
const questScrolls = shared.content.quests;
|
||||
const Schema = mongoose.Schema;
|
||||
@@ -748,63 +748,6 @@ schema.methods.leave = async function leaveGroup (user, keep = 'keep-all') {
|
||||
return await Bluebird.all(promises);
|
||||
};
|
||||
|
||||
// API v2 compatibility methods
|
||||
schema.methods.getTransformedData = function getTransformedData (options) {
|
||||
let cb = options.cb;
|
||||
let populateMembers = options.populateMembers;
|
||||
let populateInvites = options.populateInvites;
|
||||
let populateChallenges = options.populateChallenges;
|
||||
|
||||
let obj = this.toJSON();
|
||||
|
||||
let queryMembers = {};
|
||||
let queryInvites = {};
|
||||
|
||||
if (this.type === 'guild') {
|
||||
queryInvites['invitations.guilds.id'] = this._id;
|
||||
} else {
|
||||
queryInvites['invitations.party.id'] = this._id;
|
||||
}
|
||||
|
||||
if (this.type === 'guild') {
|
||||
queryMembers.guilds = this._id;
|
||||
} else {
|
||||
queryMembers['party._id'] = this._id;
|
||||
}
|
||||
|
||||
let selectDataMembers = '_id';
|
||||
let selectDataInvites = '_id';
|
||||
let selectDataChallenges = '_id';
|
||||
|
||||
if (populateMembers) {
|
||||
selectDataMembers += ` ${populateMembers}`;
|
||||
}
|
||||
if (populateInvites) {
|
||||
selectDataInvites += ` ${populateInvites}`;
|
||||
}
|
||||
if (populateChallenges) {
|
||||
selectDataChallenges += ` ${populateChallenges}`;
|
||||
}
|
||||
|
||||
let membersQuery = User.find(queryMembers).select(selectDataMembers);
|
||||
if (options.limitPopulation) membersQuery.limit(15);
|
||||
|
||||
Bluebird.all([
|
||||
membersQuery.exec(),
|
||||
User.find(queryInvites).select(populateInvites).exec(),
|
||||
Challenge.find({group: obj._id}).select(populateMembers).exec(),
|
||||
])
|
||||
.then((results) => {
|
||||
obj.members = results[0];
|
||||
obj.invites = results[1];
|
||||
obj.challenges = results[2];
|
||||
|
||||
cb(null, obj);
|
||||
})
|
||||
.catch(cb);
|
||||
};
|
||||
// END API v2 compatibility methods
|
||||
|
||||
export let model = mongoose.model('Group', schema);
|
||||
|
||||
// initialize tavern if !exists (fresh installs)
|
||||
|
||||
Reference in New Issue
Block a user