Skip to content

Commit

Permalink
fix ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed May 24, 2022
1 parent 01c258e commit 89017c8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
9 changes: 9 additions & 0 deletions apps/meteor/app/api/server/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ type ActionThis<TMethod extends Method, TPathPattern extends PathPattern, TOptio
};
/* @deprecated */
getUserFromParams(): IUser;
/* @deprecated */
getUserInfo(me: IUser): IUser & {
email?: string;
settings: {
profile: {};
preferences: unknown;
};
avatarUrl: string;
};
} & (TOptions extends { authRequired: true }
? {
readonly user: IUser;
Expand Down
4 changes: 3 additions & 1 deletion apps/meteor/app/api/server/v1/invites.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IInvite } from '@rocket.chat/core-typings';

import { API } from '../api';
import { findOrCreateInvite } from '../../../invites/server/functions/findOrCreateInvite';
import { removeInvite } from '../../../invites/server/functions/removeInvite';
Expand All @@ -22,7 +24,7 @@ API.v1.addRoute(
{
async post() {
const { rid, days, maxUses } = this.bodyParams;
const result = await findOrCreateInvite(this.userId, { rid, days, maxUses });
const result = (await findOrCreateInvite(this.userId, { rid, days, maxUses })) as IInvite;

return API.v1.success(result);
},
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/api/server/v1/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ API.v1.addRoute(
});
}

const types = settings.get('API_Shield_Types');
const types = settings.get<string>('API_Shield_Types');
if (
type &&
types !== '*' &&
Expand Down Expand Up @@ -300,7 +300,7 @@ API.v1.addRoute(
`
.trim()
.replace(/\>[\s]+\</gm, '><'),
};
} as any;
},
},
);
Expand Down
43 changes: 19 additions & 24 deletions apps/meteor/app/api/server/v1/subscriptions.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';

import { Subscriptions } from '../../../models/server';
import { Subscriptions } from '../../../models/server/raw';
import { API } from '../api';

API.v1.addRoute(
'subscriptions.get',
{ authRequired: true },
{
get() {
async get() {
const { updatedSince } = this.queryParams;

let updatedSinceDate: Date;
let updatedSinceDate: Date | undefined;
if (updatedSince) {
if (isNaN(Date.parse(updatedSince))) {
throw new Meteor.Error('error-roomId-param-invalid', 'The "lastUpdate" query parameter must be a valid date.');
} else {
updatedSinceDate = new Date(updatedSince);
}
updatedSinceDate = new Date(updatedSince);
}

let result;
Meteor.runAsUser(this.userId, () => {
result = Meteor.call('subscriptions/get', updatedSinceDate);
});

if (Array.isArray(result)) {
result = {
update: result,
remove: [],
};
}
const result = await Meteor.call('subscriptions/get', updatedSinceDate);

return API.v1.success(result);
return API.v1.success(
Array.isArray(result)
? {
update: result,
remove: [],
}
: result,
);
},
},
);
Expand All @@ -41,17 +37,15 @@ API.v1.addRoute(
'subscriptions.getOne',
{ authRequired: true },
{
get() {
const { roomId } = this.requestParams();
async get() {
const { roomId } = this.queryParams;

if (!roomId) {
return API.v1.failure("The 'roomId' param is required");
}

const subscription = Subscriptions.findOneByRoomIdAndUserId(roomId, this.userId);

return API.v1.success({
subscription,
subscription: await Subscriptions.findOneByRoomIdAndUserId(roomId, this.userId),
});
},
},
Expand All @@ -74,7 +68,7 @@ API.v1.addRoute(
rid: String,
});

Meteor.runAsUser(this.userId, () => Meteor.call('readMessages', this.bodyParams.rid));
Meteor.call('readMessages', this.bodyParams.rid);

return API.v1.success();
},
Expand All @@ -87,11 +81,12 @@ API.v1.addRoute(
{
post() {
const { roomId, firstUnreadMessage } = this.bodyParams;

if (!roomId && firstUnreadMessage && !firstUnreadMessage._id) {
return API.v1.failure('At least one of "roomId" or "firstUnreadMessage._id" params is required');
}

Meteor.runAsUser(this.userId, () => Meteor.call('unreadMessages', firstUnreadMessage, roomId));
Meteor.call('unreadMessages', firstUnreadMessage, roomId);

return API.v1.success();
},
Expand Down

0 comments on commit 89017c8

Please sign in to comment.