Skip to content

Commit

Permalink
Chore: convert import.js endpoints to TS (#25956)
Browse files Browse the repository at this point in the history
<!-- This is a pull request template, you do not need to uncomment or remove the comments, they won't show up in the PR text. -->

<!-- Your Pull Request name should start with one of the following tags
  [NEW] For new features
  [IMPROVE] For an improvement (performance or little improvements) in existing features
  [FIX] For bug fixes that affect the end-user
  [BREAK] For pull requests including breaking changes
  Chore: For small tasks
  Doc: For documentation
-->

<!-- Checklist!!! If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code. 
  - I have read the Contributing Guide - https://github.com/RocketChat/Rocket.Chat/blob/develop/.github/CONTRIBUTING.md#contributing-to-rocketchat doc
  - I have signed the CLA - https://cla-assistant.io/RocketChat/Rocket.Chat
  - Lint and unit tests pass locally with my changes
  - I have added tests that prove my fix is effective or that my feature works (if applicable)
  - I have added necessary documentation (if applicable)
  - Any dependent changes have been merged and published in downstream modules
-->

## Proposed changes (including videos or screenshots)
<!-- CHANGELOG -->
<!--
  Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.
  If it fixes a bug or resolves a feature request, be sure to link to that issue below.
  This description will appear in the release notes if we accept the contribution.
-->
Converted the `apps/meteor/app/api/server/v1/import.js` to ts and created endpoint typings on the `packages/rest-typings/src/v1/import` folder.
<!-- END CHANGELOG -->

## Issue(s)
<!-- Link the issues being closed by or related to this PR. For example, you can use #594 if this PR closes issue number 594 -->

## Steps to test or reproduce
<!-- Mention how you would reproduce the bug if not mentioned on the issue page already. Also mention which screens are going to have the changes if applicable -->

## Further comments
<!-- If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... -->
  • Loading branch information
felipe-rod123 committed Jun 22, 2022
1 parent d408c31 commit 70f5fbe
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { Meteor } from 'meteor/meteor';
import {
isUploadImportFileParamsPOST,
isDownloadPublicImportFileParamsPOST,
isStartImportParamsPOST,
isGetImportFileDataParamsGET,
isGetImportProgressParamsGET,
isGetLatestImportOperationsParamsGET,
isDownloadPendingFilesParamsPOST,
isDownloadPendingAvatarsParamsPOST,
isGetCurrentImportOperationParamsGET,
} from '@rocket.chat/rest-typings';

import { API } from '../api';
import { hasPermission } from '../../../authorization/server';
Expand All @@ -7,7 +18,10 @@ import { Importers } from '../../../importer/server';

API.v1.addRoute(
'uploadImportFile',
{ authRequired: true },
{
authRequired: true,
validateParams: isUploadImportFileParamsPOST,
},
{
post() {
const { binaryContent, contentType, fileName, importerKey } = this.bodyParams;
Expand All @@ -19,7 +33,10 @@ API.v1.addRoute(

API.v1.addRoute(
'downloadPublicImportFile',
{ authRequired: true },
{
authRequired: true,
validateParams: isDownloadPublicImportFileParamsPOST,
},
{
post() {
const { fileUrl, importerKey } = this.bodyParams;
Expand All @@ -35,7 +52,10 @@ API.v1.addRoute(

API.v1.addRoute(
'startImport',
{ authRequired: true },
{
authRequired: true,
validateParams: isStartImportParamsPOST,
},
{
post() {
const { input } = this.bodyParams;
Expand All @@ -51,7 +71,10 @@ API.v1.addRoute(

API.v1.addRoute(
'getImportFileData',
{ authRequired: true },
{
authRequired: true,
validateParams: isGetImportFileDataParamsGET,
},
{
get() {
let result;
Expand All @@ -66,7 +89,10 @@ API.v1.addRoute(

API.v1.addRoute(
'getImportProgress',
{ authRequired: true },
{
authRequired: true,
validateParams: isGetImportProgressParamsGET,
},
{
get() {
let result;
Expand All @@ -81,7 +107,10 @@ API.v1.addRoute(

API.v1.addRoute(
'getLatestImportOperations',
{ authRequired: true },
{
authRequired: true,
validateParams: isGetLatestImportOperationsParamsGET,
},
{
get() {
let result;
Expand All @@ -96,7 +125,10 @@ API.v1.addRoute(

API.v1.addRoute(
'downloadPendingFiles',
{ authRequired: true },
{
authRequired: true,
validateParams: isDownloadPendingFilesParamsPOST,
},
{
post() {
if (!this.userId) {
Expand Down Expand Up @@ -129,7 +161,10 @@ API.v1.addRoute(

API.v1.addRoute(
'downloadPendingAvatars',
{ authRequired: true },
{
authRequired: true,
validateParams: isDownloadPendingAvatarsParamsPOST,
},
{
post() {
if (!this.userId) {
Expand Down Expand Up @@ -162,7 +197,10 @@ API.v1.addRoute(

API.v1.addRoute(
'getCurrentImportOperation',
{ authRequired: true },
{
authRequired: true,
validateParams: isGetCurrentImportOperationParamsGET,
},
{
get() {
if (!this.userId) {
Expand Down
9 changes: 9 additions & 0 deletions packages/rest-typings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,12 @@ export * from './v1/users/UsersSetAvatarParamsPOST';
export * from './v1/users/UsersSetPreferenceParamsPOST';
export * from './v1/users/UsersUpdateOwnBasicInfoParamsPOST';
export * from './v1/users/UsersUpdateParamsPOST';
export * from './v1/import/UploadImportFileParamsPOST';
export * from './v1/import/DownloadPublicImportFileParamsPOST';
export * from './v1/import/StartImportParamsPOST';
export * from './v1/import/GetImportFileDataParamsGET';
export * from './v1/import/GetImportProgressParamsGET';
export * from './v1/import/GetLatestImportOperationsParamsGET';
export * from './v1/import/DownloadPendingFilesParamsPOST';
export * from './v1/import/DownloadPendingAvatarsParamsPOST';
export * from './v1/import/GetCurrentImportOperationParamsGET';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type DownloadPendingAvatarsParamsPOST = {
userId: string;
count: number;
};

const DownloadPendingAvatarsParamsPOSTSchema = {
type: 'object',
properties: {
userId: {
type: 'string',
},
count: {
type: 'number',
},
},
additionalProperties: false,
required: ['userId', 'count'],
};

export const isDownloadPendingAvatarsParamsPOST = ajv.compile<DownloadPendingAvatarsParamsPOST>(DownloadPendingAvatarsParamsPOSTSchema);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type DownloadPendingFilesParamsPOST = {
userId: string;
count: number;
};

const DownloadPendingFilesParamsPOSTSchema = {
type: 'object',
properties: {
userId: {
type: 'string',
},
count: {
type: 'number',
},
},
additionalProperties: false,
required: ['userId', 'count'],
};

export const isDownloadPendingFilesParamsPOST = ajv.compile<DownloadPendingFilesParamsPOST>(DownloadPendingFilesParamsPOSTSchema);
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type DownloadPublicImportFileParamsPOST = {
fileUrl: string;
importerKey: string;
};

const DownloadPublicImportFileParamsPostSchema = {
type: 'object',
properties: {
fileUrl: {
type: 'string',
},
importerKey: {
type: 'string',
},
},
additionalProperties: false,
required: ['fileUrl', 'importerKey'],
};

export const isDownloadPublicImportFileParamsPOST = ajv.compile<DownloadPublicImportFileParamsPOST>(
DownloadPublicImportFileParamsPostSchema,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type GetCurrentImportOperationParamsGET = {
userId: string;
operation: string;
};

const GetCurrentImportOperationParamsGETSchema = {
type: 'object',
properties: {
userId: {
type: 'string',
},
operation: {
type: 'string',
},
},
additionalProperties: false,
required: ['userId', 'operation'],
};

export const isGetCurrentImportOperationParamsGET = ajv.compile<GetCurrentImportOperationParamsGET>(
GetCurrentImportOperationParamsGETSchema,
);
22 changes: 22 additions & 0 deletions packages/rest-typings/src/v1/import/GetImportFileDataParamsGET.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type GetImportFileDataParamsGET = {
userId: string;
};

const GetImportFileDataParamsGETSchema = {
type: 'object',
properties: {
userId: {
type: 'string',
},
},
additionalProperties: false,
required: ['userId'],
};

export const isGetImportFileDataParamsGET = ajv.compile<GetImportFileDataParamsGET>(GetImportFileDataParamsGETSchema);
22 changes: 22 additions & 0 deletions packages/rest-typings/src/v1/import/GetImportProgressParamsGET.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type GetImportProgressParamsGET = {
userId: string;
};

const GetImportProgressParamsGETSchema = {
type: 'object',
properties: {
userId: {
type: 'string',
},
},
additionalProperties: false,
required: ['userId'],
};

export const isGetImportProgressParamsGET = ajv.compile<GetImportProgressParamsGET>(GetImportProgressParamsGETSchema);
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type GetLatestImportOperationsParamsGET = {
userId: string;
};

const GetLatestImportOperationsParamsGETSchema = {
type: 'object',
properties: {
userId: {
type: 'string',
},
},
additionalProperties: false,
required: ['userId'],
};

export const isGetLatestImportOperationsParamsGET = ajv.compile<GetLatestImportOperationsParamsGET>(
GetLatestImportOperationsParamsGETSchema,
);
22 changes: 22 additions & 0 deletions packages/rest-typings/src/v1/import/StartImportParamsPOST.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Ajv, { JSONSchemaType } from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type StartImportParamsPOST = {
input: string;
};

const StartImportParamsPostSchema: JSONSchemaType<StartImportParamsPOST> = {
type: 'object',
properties: {
input: {
type: 'string',
},
},
additionalProperties: false,
required: ['input'],
};

export const isStartImportParamsPOST = ajv.compile<StartImportParamsPOST>(StartImportParamsPostSchema);
34 changes: 34 additions & 0 deletions packages/rest-typings/src/v1/import/UploadImportFileParamsPOST.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type UploadImportFileParamsPOST = {
binaryContent: string;
contentType: string;
fileName: string;
importerKey: string;
};

const UploadImportFileParamsPostSchema = {
type: 'object',
properties: {
binaryContent: {
type: 'string',
},
contentType: {
type: 'string',
},
fileName: {
type: 'string',
},
importerKey: {
type: 'string',
},
},
additionalProperties: false,
required: ['binaryContent', 'contentType', 'fileName', 'importerKey'],
};

export const isUploadImportFileParamsPOST = ajv.compile<UploadImportFileParamsPOST>(UploadImportFileParamsPostSchema);
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7690,7 +7690,7 @@ __metadata:
human-interval: ~1.0.0
moment-timezone: ~0.5.27
mongodb: ~3.5.0
checksum: acb4ebb7e7356f6e53e810d821eb6aa3d88bbfb9e85183e707517bee6d1eea1f189f38bdf0dd2b91360492ab7643134d510c320d2523d86596498ab98e59735b
checksum: cc8c1bbba7545628d9d039c58e701ff65cf07f241f035b731716eec0d5ef906ce09d60c3b321bbfb9e6c641994d1afd23aaeb92d645b33bf7be9942f13574173
languageName: node
linkType: hard

Expand Down

0 comments on commit 70f5fbe

Please sign in to comment.