forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RocketChat#764 [NEW] Форма подачи документов
- Loading branch information
Showing
38 changed files
with
2,129 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { WorkingGroupsRequests } from '../../../models/server/raw'; | ||
|
||
export async function findWorkingGroupsRequests({ query = {}, pagination: { offset, count, sort } }) { | ||
const cursor = await WorkingGroupsRequests.find(query, { | ||
sort: sort || { time: 1 }, | ||
skip: offset, | ||
limit: count, | ||
}); | ||
|
||
const total = await cursor.count(); | ||
|
||
const requests = await cursor.toArray(); | ||
|
||
return { | ||
requests, | ||
count: requests.length, | ||
offset, | ||
total, | ||
}; | ||
} | ||
|
||
export async function findOneWorkingGroupRequestByInviteLink(inviteLink) { | ||
const cursor = await WorkingGroupsRequests.findWorkingGroupRequestByInviteLink({ inviteLink }, {}); | ||
return cursor; | ||
} | ||
export async function findWorkingGroupRequest(_id) { | ||
const cursor = await WorkingGroupsRequests.findOne({ _id }); | ||
return cursor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import Busboy from 'busboy'; | ||
import { Meteor } from 'meteor/meteor'; | ||
|
||
import { API } from '../api'; | ||
import { FileUpload } from '../../../file-upload'; | ||
import { findWorkingGroupsRequests, findOneWorkingGroupRequestByInviteLink, findWorkingGroupRequest } from '../lib/working-groups-requests'; | ||
|
||
API.v1.addRoute('working-groups-requests.list', { authRequired: true }, { | ||
get() { | ||
const { offset, count } = this.getPaginationItems(); | ||
const { sort, query } = this.parseJsonQuery(); | ||
|
||
return API.v1.success(Promise.await(findWorkingGroupsRequests({ | ||
query, | ||
pagination: { | ||
offset, | ||
count, | ||
sort, | ||
}, | ||
}))); | ||
}, | ||
}); | ||
|
||
API.v1.addRoute('working-groups-requests.findOne', { authRequired: true }, { | ||
get() { | ||
const { query } = this.parseJsonQuery(); | ||
return API.v1.success(Promise.await(findWorkingGroupRequest(query._id))); | ||
}, | ||
}); | ||
|
||
API.v1.addRoute('working-groups-requests.getOneByInviteLink', { authRequired: false }, { | ||
get() { | ||
const { query } = this.parseJsonQuery(); | ||
return API.v1.success(Promise.await(findOneWorkingGroupRequestByInviteLink(query.inviteLink))); | ||
}, | ||
}); | ||
|
||
const getFiles = Meteor.wrapAsync(({ request }, callback) => { | ||
const busboy = new Busboy({ headers: request.headers }); | ||
const files = []; | ||
|
||
const fields = {}; | ||
|
||
|
||
busboy.on('file', (fieldname, file, filename, encoding, mimetype) => { | ||
if (fieldname !== 'file') { | ||
return callback(new Meteor.Error('invalid-field')); | ||
} | ||
|
||
const fileDate = []; | ||
file.on('data', (data) => fileDate.push(data)); | ||
|
||
file.on('end', () => { | ||
files.push({ fieldname, file, filename, encoding, mimetype, fileBuffer: Buffer.concat(fileDate) }); | ||
}); | ||
}); | ||
|
||
busboy.on('field', (fieldname, value) => { fields[fieldname] = value; }); | ||
|
||
busboy.on('finish', Meteor.bindEnvironment(() => callback(null, { files, fields }))); | ||
|
||
request.pipe(busboy); | ||
}); | ||
|
||
API.v1.addRoute('working-groups-requests.upload/:id/:mailId/:answerId', { authRequired: false }, { | ||
post() { | ||
const { files, fields } = getFiles({ | ||
request: this.request, | ||
}); | ||
|
||
if (files.length === 0) { | ||
console.log('api.v1.route file required'); | ||
return API.v1.failure('File required'); | ||
} | ||
|
||
if (files.length > 1) { | ||
console.log('api.v1.route just 3 file is allowed'); | ||
return API.v1.failure('Just 3 file is allowed'); | ||
} | ||
|
||
const file = files[0]; | ||
|
||
const details = { | ||
name: file.filename, | ||
size: file.fileBuffer.length, | ||
type: file.mimetype, | ||
workingGroupRequestId: this.urlParams.id, | ||
workingGroupRequestMailId: this.urlParams.mailId, | ||
workingGroupRequestAnswerId: this.urlParams.answerId, | ||
}; | ||
|
||
// TODO: Requires user ID to upload file | ||
const fileData = Meteor.runAsUser('rocket.cat', () => { | ||
const fileStore = FileUpload.getStore('Uploads'); | ||
const uploadedFile = fileStore.insertSync(details, file.fileBuffer); | ||
|
||
uploadedFile.description = fields.description; | ||
return uploadedFile; | ||
}); | ||
return API.v1.success({ _id: fileData._id }); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.