Skip to content

Commit

Permalink
Merge 4b1af7f into 039439d
Browse files Browse the repository at this point in the history
  • Loading branch information
paglias committed Jun 17, 2018
2 parents 039439d + 4b1af7f commit c91ae4b
Show file tree
Hide file tree
Showing 46 changed files with 176 additions and 172 deletions.
12 changes: 6 additions & 6 deletions test/client/unit/specs/libs/asyncResource.js
Expand Up @@ -80,12 +80,12 @@ describe('async resource', () => {
const store = generateStore();
store.state.user = asyncResourceFactory();

sandbox.stub(axios, 'get').withArgs('/api/v3/user').returns(Promise.resolve({data: {data: {_id: 1}}}));
sandbox.stub(axios, 'get').withArgs('/api/v4/user').returns(Promise.resolve({data: {data: {_id: 1}}}));

const resource = await loadAsyncResource({
store,
path: 'user',
url: '/api/v3/user',
url: '/api/v4/user',
deserialize (response) {
return response.data.data;
},
Expand All @@ -101,12 +101,12 @@ describe('async resource', () => {
const store = generateStore();
store.state.user.loadingStatus = 'LOADED';

sandbox.stub(axios, 'get').withArgs('/api/v3/user').returns(Promise.resolve({data: {data: {_id: 1}}}));
sandbox.stub(axios, 'get').withArgs('/api/v4/user').returns(Promise.resolve({data: {data: {_id: 1}}}));

const resource = await loadAsyncResource({
store,
path: 'user',
url: '/api/v3/user',
url: '/api/v4/user',
deserialize (response) {
return response.data.data;
},
Expand All @@ -123,12 +123,12 @@ describe('async resource', () => {
const store = generateStore();
store.state.user.loadingStatus = 'LOADING';

sandbox.stub(axios, 'get').withArgs('/api/v3/user').returns(Promise.resolve({data: {data: {_id: 1}}}));
sandbox.stub(axios, 'get').withArgs('/api/v4/user').returns(Promise.resolve({data: {data: {_id: 1}}}));

const resourcePromise = loadAsyncResource({
store,
path: 'user',
url: '/api/v3/user',
url: '/api/v4/user',
deserialize (response) {
return response.data.data;
},
Expand Down
2 changes: 1 addition & 1 deletion test/client/unit/specs/store/actions/shops.js
Expand Up @@ -39,7 +39,7 @@ describe('shops actions', () => {

let item = getItemInfo(user, 'marketGear', gearItem, getOfficialPinnedItems(user));

sandbox.stub(axios, 'post').withArgs('/api/v3/user/buy/armor_rogue_1').returns(Promise.resolve({data: {data: {}}}));
sandbox.stub(axios, 'post').withArgs('/api/v4/user/buy/armor_rogue_1').returns(Promise.resolve({data: {data: {}}}));

await store.dispatch('shops:genericPurchase', {
pinType: item.pinType,
Expand Down
6 changes: 3 additions & 3 deletions test/client/unit/specs/store/actions/tasks.js
Expand Up @@ -12,7 +12,7 @@ describe('tasks actions', () => {
xit('fetches user tasks', async () => {
expect(store.state.tasks.loadingStatus).to.equal('NOT_LOADED');
const tasks = [{_id: 1}];
sandbox.stub(axios, 'get').withArgs('/api/v3/tasks/user').returns(Promise.resolve({data: {data: tasks}}));
sandbox.stub(axios, 'get').withArgs('/api/v4/tasks/user').returns(Promise.resolve({data: {data: tasks}}));

await store.dispatch('tasks:fetchUserTasks');

Expand All @@ -28,7 +28,7 @@ describe('tasks actions', () => {
};

const tasks = [{_id: 2}];
sandbox.stub(axios, 'get').withArgs('/api/v3/tasks/user').returns(Promise.resolve({data: {data: tasks}}));
sandbox.stub(axios, 'get').withArgs('/api/v4/tasks/user').returns(Promise.resolve({data: {data: tasks}}));

await store.dispatch('tasks:fetchUserTasks');

Expand All @@ -43,7 +43,7 @@ describe('tasks actions', () => {
};

const tasks = [{_id: 2}];
sandbox.stub(axios, 'get').withArgs('/api/v3/tasks/user').returns(Promise.resolve({data: {data: tasks}}));
sandbox.stub(axios, 'get').withArgs('/api/v4/tasks/user').returns(Promise.resolve({data: {data: tasks}}));

await store.dispatch('tasks:fetchUserTasks', true);

Expand Down
6 changes: 3 additions & 3 deletions test/client/unit/specs/store/actions/user.js
Expand Up @@ -12,7 +12,7 @@ describe('user actions', () => {
it('loads the user', async () => {
expect(store.state.user.loadingStatus).to.equal('NOT_LOADED');
const user = {_id: 1};
sandbox.stub(axios, 'get').withArgs('/api/v3/user').returns(Promise.resolve({data: {data: user}}));
sandbox.stub(axios, 'get').withArgs('/api/v4/user').returns(Promise.resolve({data: {data: user}}));

await store.dispatch('user:fetch');

Expand All @@ -28,7 +28,7 @@ describe('user actions', () => {
};

const user = {_id: 2};
sandbox.stub(axios, 'get').withArgs('/api/v3/user').returns(Promise.resolve({data: {data: user}}));
sandbox.stub(axios, 'get').withArgs('/api/v4/user').returns(Promise.resolve({data: {data: user}}));

await store.dispatch('user:fetch');

Expand All @@ -43,7 +43,7 @@ describe('user actions', () => {
};

const user = {_id: 2};
sandbox.stub(axios, 'get').withArgs('/api/v3/user').returns(Promise.resolve({data: {data: user}}));
sandbox.stub(axios, 'get').withArgs('/api/v4/user').returns(Promise.resolve({data: {data: user}}));

await store.dispatch('user:fetch', {forceLoad: true});

Expand Down
6 changes: 5 additions & 1 deletion webpack/config/index.js
Expand Up @@ -41,11 +41,15 @@ module.exports = {
assetsPublicPath: '/',
staticAssetsDirectory,
proxyTable: {
// proxy all requests starting with /api/v3 to IP:PORT as specified in the top-level config
// proxy all requests to the server at IP:PORT as specified in the top-level config
'/api/v3': {
target: DEV_BASE_URL,
changeOrigin: true,
},
'/api/v4': {
target: DEV_BASE_URL,
changeOrigin: true,
},
'/stripe': {
target: DEV_BASE_URL,
changeOrigin: true,
Expand Down
12 changes: 6 additions & 6 deletions website/client/app.vue
Expand Up @@ -306,7 +306,7 @@ export default {
// Don't show errors from getting user details. These users have delete their account,
// but their chat message still exists.
let configExists = Boolean(error.response) && Boolean(error.response.config);
if (configExists && error.response.config.method === 'get' && error.response.config.url.indexOf('/api/v3/members/') !== -1) {
if (configExists && error.response.config.method === 'get' && error.response.config.url.indexOf('/api/v4/members/') !== -1) {
// @TODO: We resolve the promise because we need our caching to cache this user as tried
// Chat paging should help this, but maybe we can also find another solution..
return Promise.resolve(error);
Expand Down Expand Up @@ -348,20 +348,20 @@ export default {
const url = response.config.url;
const method = response.config.method;
const isApiCall = url.indexOf('api/v3') !== -1;
const isApiCall = url.indexOf('api/v4') !== -1;
const userV = response.data && response.data.userV;
const isCron = url.indexOf('/api/v3/cron') === 0 && method === 'post';
const isCron = url.indexOf('/api/v4/cron') === 0 && method === 'post';
if (this.isUserLoaded && isApiCall && userV) {
const oldUserV = this.user._v;
this.user._v = userV;
// Do not sync again if already syncing
const isUserSync = url.indexOf('/api/v3/user') === 0 && method === 'get';
const isTasksSync = url.indexOf('/api/v3/tasks/user') === 0 && method === 'get';
const isUserSync = url.indexOf('/api/v4/user') === 0 && method === 'get';
const isTasksSync = url.indexOf('/api/v4/tasks/user') === 0 && method === 'get';
// exclude chat seen requests because with real time chat they would be too many
const isChatSeen = url.indexOf('/chat/seen') !== -1 && method === 'post';
// exclude POST /api/v3/cron because the user is synced automatically after cron runs
// exclude POST /api/v4/cron because the user is synced automatically after cron runs
// Something has changed on the user object that was not tracked here, sync the user
if (userV - oldUserV > 1 && !isCron && !isChatSeen && !isUserSync && !isTasksSync) {
Expand Down
2 changes: 1 addition & 1 deletion website/client/components/achievements/death.vue
Expand Up @@ -66,7 +66,7 @@ export default {
this.$root.$emit('bv::hide::modal', 'death');
},
async revive () {
await axios.post('/api/v3/user/revive');
await axios.post('/api/v4/user/revive');
revive(this.user);
this.close();
},
Expand Down
2 changes: 1 addition & 1 deletion website/client/components/achievements/newStuff.vue
Expand Up @@ -40,7 +40,7 @@
async mounted () {
this.$root.$on('bv::show::modal', async (modalId) => {
if (modalId !== 'new-stuff') return;
let response = await axios.get('/api/v3/news');
let response = await axios.get('/api/v4/news');
this.html = response.data.html;
});
},
Expand Down
10 changes: 5 additions & 5 deletions website/client/components/appFooter.vue
Expand Up @@ -308,20 +308,20 @@ export default {
let date = moment(this.user.lastCron).subtract(numberOfDays, 'days').toDate();
await axios.post('/api/v3/debug/set-cron', {
await axios.post('/api/v4/debug/set-cron', {
lastCron: date,
});
// @TODO: Notification.text('-' + numberOfDays + ' day(s), remember to refresh');
// @TODO: Sync user?
},
async addTenGems () {
await axios.post('/api/v3/debug/add-ten-gems');
await axios.post('/api/v4/debug/add-ten-gems');
// @TODO: Notification.text('+10 Gems!');
this.user.balance += 2.5;
},
async addHourglass () {
await axios.post('/api/v3/debug/add-hourglass');
await axios.post('/api/v4/debug/add-hourglass');
// @TODO: Sync?
},
addGold () {
Expand Down Expand Up @@ -356,13 +356,13 @@ export default {
});
},
async addQuestProgress () {
await axios.post('/api/v3/debug/quest-progress');
await axios.post('/api/v4/debug/quest-progress');
// @TODO: Notification.text('Quest progress increased');
// @TODO: User.sync();
},
async makeAdmin () {
await axios.post('/api/v3/debug/make-admin');
await axios.post('/api/v4/debug/make-admin');
// @TODO: Notification.text('You are now an admin! Go to the Hall of Heroes to change your contributor level.');
// @TODO: sync()
Expand Down
6 changes: 3 additions & 3 deletions website/client/components/auth/registerLoginReset.vue
Expand Up @@ -370,7 +370,7 @@ export default {
}
// @TODO: implement langauge and invite accepting
// var url = ApiUrl.get() + "/api/v3/user/auth/local/register";
// var url = ApiUrl.get() + "/api/v4/user/auth/local/register";
// if (location.search && location.search.indexOf('Invite=') !== -1) { // matches groupInvite and partyInvite
// url += location.search;
// }
Expand Down Expand Up @@ -481,7 +481,7 @@ export default {
return;
}
await axios.post('/api/v3/user/reset-password', {
await axios.post('/api/v4/user/reset-password', {
email: this.username,
});
Expand All @@ -499,7 +499,7 @@ export default {
return;
}
const res = await axios.post('/api/v3/user/auth/reset-password-set-new-one', {
const res = await axios.post('/api/v4/user/auth/reset-password-set-new-one', {
newPassword: this.password,
confirmPassword: this.passwordConfirm,
code: this.resetPasswordSetNewOneData.code,
Expand Down
2 changes: 1 addition & 1 deletion website/client/components/challenges/challengeDetail.vue
Expand Up @@ -381,7 +381,7 @@ export default {
// let response = await this.$store.dispatch('challenges:exportChallengeCsv', {
// challengeId: this.searchId,
// });
window.location = `/api/v3/challenges/${this.searchId}/export/csv`;
window.location = `/api/v4/challenges/${this.searchId}/export/csv`;
},
cloneChallenge () {
this.$root.$emit('habitica:clone-challenge', {
Expand Down
Expand Up @@ -38,7 +38,7 @@ export default {
reward: [],
};
let response = await axios.get(`/api/v3/challenges/${this.challengeId}/members/${this.memberId}`);
let response = await axios.get(`/api/v4/challenges/${this.challengeId}/members/${this.memberId}`);
let tasks = response.data.data.tasks;
tasks.forEach((task) => {
this.tasksByType[task.type].push(task);
Expand Down
2 changes: 1 addition & 1 deletion website/client/components/chat/chatCard.vue
Expand Up @@ -253,7 +253,7 @@ export default {
this.$emit('message-removed', message);
if (this.inbox) {
axios.delete(`/api/v3/user/messages/${message.id}`);
axios.delete(`/api/v4/user/messages/${message.id}`);
this.$delete(this.user.inbox.messages, message.id);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion website/client/components/chat/chatMessages.vue
Expand Up @@ -164,7 +164,7 @@ export default {
if (Boolean(uuid) && !this.cachedProfileData[uuid] && !aboutToCache[uuid]) {
if (uuid === 'system' || this.currentProfileLoadedCount === this.currentProfileLoadedEnd) return;
aboutToCache[uuid] = {};
promises.push(axios.get(`/api/v3/members/${uuid}`));
promises.push(axios.get(`/api/v4/members/${uuid}`));
this.currentProfileLoadedCount += 1;
}
});
Expand Down
4 changes: 2 additions & 2 deletions website/client/components/creatorIntro.vue
Expand Up @@ -1441,7 +1441,7 @@ export default {
});
// @TODO: Move to the action
let response = await axios.post('/api/v3/tasks/user', tasksToCreate);
let response = await axios.post('/api/v4/tasks/user', tasksToCreate);
let tasks = response.data.data;
tasks.forEach(task => {
this.$store.state.user.data.tasksOrder[`${task.type}s`].unshift(task._id);
Expand Down Expand Up @@ -1512,7 +1512,7 @@ export default {
}
}
await axios.post(`/api/v3/user/unlock?path=${path}`);
await axios.post(`/api/v4/user/unlock?path=${path}`);
try {
unlock(this.user, {
query: {
Expand Down
2 changes: 1 addition & 1 deletion website/client/components/header/userDropdown.vue
Expand Up @@ -98,7 +98,7 @@ export default {
},
showInbox () {
markPMSRead(this.user);
axios.post('/api/v3/user/mark-pms-read');
axios.post('/api/v4/user/mark-pms-read');
this.$root.$emit('bv::show::modal', 'inbox-modal');
},
showProfile (startingPage) {
Expand Down
2 changes: 1 addition & 1 deletion website/client/components/inventory/items/cards-modal.vue
Expand Up @@ -54,7 +54,7 @@ export default {
},
methods: {
async readCard () {
await axios.post(`/api/v3/user/read-card/${this.cardType}`);
await axios.post(`/api/v4/user/read-card/${this.cardType}`);
this.user.items.special[`${this.cardType}Received`].shift();
this.user.flags.cardReceived = false;
this.close();
Expand Down
2 changes: 1 addition & 1 deletion website/client/components/modifyInventory.vue
Expand Up @@ -294,7 +294,7 @@ export default {
}
},
async modifyInventory () {
await axios.post('/api/v3/debug/modify-inventory', {
await axios.post('/api/v4/debug/modify-inventory', {
gear: this.showInv.gear ? this.inv.gear : null,
special: this.showInv.special ? this.inv.special : null,
pets: this.showInv.pets ? this.inv.pets : null,
Expand Down
4 changes: 2 additions & 2 deletions website/client/components/notifications.vue
Expand Up @@ -399,7 +399,7 @@ export default {
},
async runYesterDailiesAction () {
// Run Cron
await axios.post('/api/v3/cron');
await axios.post('/api/v4/cron');
// Notifications
Expand Down Expand Up @@ -532,7 +532,7 @@ export default {
let userReadNotifsPromise = false;
if (notificationsToRead.length > 0) {
await axios.post('/api/v3/notifications/read', {
await axios.post('/api/v4/notifications/read', {
notificationIds: notificationsToRead,
});
}
Expand Down
2 changes: 1 addition & 1 deletion website/client/components/payments/amazonModal.vue
Expand Up @@ -206,7 +206,7 @@ export default {
let url = '/amazon/subscribe';
if (this.amazonPayments.groupToCreate) {
url = '/api/v3/groups/create-plan';
url = '/api/v4/groups/create-plan';
}
try {
Expand Down
2 changes: 1 addition & 1 deletion website/client/components/settings/deleteModal.vue
Expand Up @@ -47,7 +47,7 @@ export default {
this.$root.$emit('bv::hide::modal', 'reset');
},
async deleteAccount () {
await axios.delete('/api/v3/user', {
await axios.delete('/api/v4/user', {
data: {
password: this.password,
feedback: this.feedback,
Expand Down
4 changes: 2 additions & 2 deletions website/client/components/settings/promoCode.vue
Expand Up @@ -40,7 +40,7 @@ export default {
...mapState({user: 'user.data', credentials: 'credentials'}),
getCodesUrl () {
if (!this.user) return '';
return `/api/v3/coupons?_id=${this.user._id}&apiToken=${this.credentials.API_TOKEN}`;
return `/api/v4/coupons?_id=${this.user._id}&apiToken=${this.credentials.API_TOKEN}`;
},
},
methods: {
Expand All @@ -53,7 +53,7 @@ export default {
// })
},
async enterCoupon () {
let code = await axios.post(`/api/v3/coupons/enter/${this.couponCode}`);
let code = await axios.post(`/api/v4/coupons/enter/${this.couponCode}`);
if (!code) return;
this.$store.state.user.data = code.data.data;
Expand Down
2 changes: 1 addition & 1 deletion website/client/components/settings/resetModal.vue
Expand Up @@ -20,7 +20,7 @@ export default {
this.$root.$emit('bv::hide::modal', 'reset');
},
async reset () {
let response = await axios.post('/api/v3/user/reset');
let response = await axios.post('/api/v4/user/reset');
// @TODO: Not sure if this is correct
this.$store.user = response.data.data.user;
this.$router.push('/');
Expand Down

0 comments on commit c91ae4b

Please sign in to comment.