Skip to content

Commit 619ccb2

Browse files
committed
Return removed stuff
1 parent 3de42b7 commit 619ccb2

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

src/resolvers/billingNew.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '@hawk.so/types';
1010
import checksumService from '../utils/checksumService';
1111
import { UserInputError } from 'apollo-server-express';
12+
import cloudPaymentsApi, { CloudPaymentsJsonData } from '../utils/cloudPaymentsApi';
1213

1314
/**
1415
* The amount we will debit to confirm the subscription.
@@ -154,7 +155,7 @@ export default {
154155
throw new UserInputError('There is no saved card with provided id');
155156
}
156157

157-
const jsonData: any = {
158+
const jsonData: CloudPaymentsJsonData = {
158159
checksum: args.input.checksum,
159160
};
160161

@@ -192,7 +193,15 @@ export default {
192193
amount = AMOUNT_FOR_CARD_VALIDATION;
193194
}
194195

195-
const operation = await factories.businessOperationsFactory.getBusinessOperationByTransactionId('foo');
196+
const result = await cloudPaymentsApi.payByToken({
197+
AccountId: user.id,
198+
Amount: amount,
199+
Token: token,
200+
Currency: 'RUB',
201+
JsonData: jsonData,
202+
});
203+
204+
const operation = await factories.businessOperationsFactory.getBusinessOperationByTransactionId(result.Model.TransactionId.toString());
196205

197206
return {
198207
recordId: operation?._id,

src/resolvers/event.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,53 @@ module.exports = {
122122
return release;
123123
},
124124
},
125+
Subscription: {
126+
eventOccurred: {
127+
/**
128+
* Subscribes user to events from his projects
129+
* @param {ResolverObj} _obj
130+
* @param {Object} _args - request variables (not used)
131+
* @param {UserInContext} user - current authorized user {@see ../index.js}
132+
* @param {ContextFactories} factories - factories for working with models
133+
* @return {AsyncIterator<EventSchema>}
134+
*/
135+
subscribe: async (_obj, _args, { user, factories }) => {
136+
const userId = user.id;
137+
const userModel = await factories.usersFactory.findById(userId);
138+
// eslint-disable-next-line no-async-promise-executor
139+
const eventsCollections = new Promise(async resolve => {
140+
// @todo optimize query for getting all user's projects
141+
142+
// Find all user's workspaces
143+
const allWorkspacesIds = await userModel.getWorkspacesIds();
144+
const allProjects = [];
145+
146+
// Find all user's projects
147+
await asyncForEach(allWorkspacesIds, async workspaceId => {
148+
const allProjectsInWorkspace = await new ProjectToWorkspace(workspaceId).getProjects();
149+
150+
allProjects.push(...allProjectsInWorkspace);
151+
});
152+
153+
resolve(allProjects.map(project =>
154+
mongo.databases.events
155+
.collection('events:' + project.id)
156+
));
157+
});
158+
159+
return watchController.getAsyncIteratorForCollectionChangesEvents(eventsCollections);
160+
},
161+
162+
/**
163+
* Sends data to user about new events
164+
* @param {Object} payload - subscription event payload (from mongoDB watch)
165+
* @return {EventSchema}
166+
*/
167+
resolve: (payload) => {
168+
return payload.fullDocument;
169+
},
170+
},
171+
},
125172
Mutation: {
126173
/**
127174
* Mark event as visited for current user

src/typeDefs/event.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,13 @@ type DailyEventInfo {
394394
lastRepetitionTime: Float!
395395
}
396396
397+
type Subscription {
398+
"""
399+
Sends new events from all user projects
400+
"""
401+
eventOccurred: Event! @requireAuth
402+
}
403+
397404
"""
398405
Event information per day with these events
399406
"""

0 commit comments

Comments
 (0)