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.
[IMPROVE] Replace customSounds publication by REST (RocketChat#15907)
- Loading branch information
1 parent
da79cdf
commit c93e9d1
Showing
12 changed files
with
137 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { CustomSounds } from '../../../models/server/raw'; | ||
|
||
export async function findCustomSounds({ query = {}, pagination: { offset, count, sort } }) { | ||
const cursor = await CustomSounds.find(query, { | ||
sort: sort || { name: 1 }, | ||
skip: offset, | ||
limit: count, | ||
}); | ||
|
||
const total = await cursor.count(); | ||
|
||
const sounds = await cursor.toArray(); | ||
|
||
return { | ||
sounds, | ||
count: sounds.length, | ||
offset, | ||
total, | ||
}; | ||
} |
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,18 @@ | ||
import { API } from '../api'; | ||
import { findCustomSounds } from '../lib/custom-sounds'; | ||
|
||
API.v1.addRoute('custom-sounds.list', { authRequired: true }, { | ||
get() { | ||
const { offset, count } = this.getPaginationItems(); | ||
const { sort, query } = this.parseJsonQuery(); | ||
|
||
return API.v1.success(Promise.await(findCustomSounds({ | ||
query, | ||
pagination: { | ||
offset, | ||
count, | ||
sort, | ||
}, | ||
}))); | ||
}, | ||
}); |
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
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
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,5 @@ | ||
import { BaseRaw } from './BaseRaw'; | ||
|
||
export class CustomSoundsRaw extends BaseRaw { | ||
|
||
} |
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,22 @@ | ||
import { getCredentials, api, request, credentials } from '../../data/api-data.js'; | ||
|
||
describe('[CustomSounds]', function() { | ||
this.retries(0); | ||
|
||
before((done) => getCredentials(done)); | ||
|
||
describe('[/custom-sounds.list]', () => { | ||
it('should return custom sounds', (done) => { | ||
request.get(api('custom-sounds.list')) | ||
.set(credentials) | ||
.expect(200) | ||
.expect((res) => { | ||
expect(res.body).to.have.property('sounds').and.to.be.an('array'); | ||
expect(res.body).to.have.property('total'); | ||
expect(res.body).to.have.property('offset'); | ||
expect(res.body).to.have.property('count'); | ||
}) | ||
.end(done); | ||
}); | ||
}); | ||
}); |