Refactor
This commit is contained in:
parent
b7d62d09ec
commit
13e43a4f74
|
@ -1,9 +1,9 @@
|
||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import ID, { transform } from '../../../../../misc/cafy-id';
|
import ID, { transform } from '../../../../../misc/cafy-id';
|
||||||
import Favorite from '../../../../../models/favorite';
|
import Favorite from '../../../../../models/favorite';
|
||||||
import Note from '../../../../../models/note';
|
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
import { getNote } from '../../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
stability: 'stable',
|
stability: 'stable',
|
||||||
|
@ -45,14 +45,11 @@ export const meta = {
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
export default define(meta, async (ps, user) => {
|
||||||
// Get favoritee
|
// Get favoritee
|
||||||
const note = await Note.findOne({
|
const note = await getNote(ps.noteId).catch(e => {
|
||||||
_id: ps.noteId
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (note === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchNote);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if already favorited
|
// if already favorited
|
||||||
const exist = await Favorite.findOne({
|
const exist = await Favorite.findOne({
|
||||||
noteId: note._id,
|
noteId: note._id,
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import ID, { transform } from '../../../../../misc/cafy-id';
|
import ID, { transform } from '../../../../../misc/cafy-id';
|
||||||
import Favorite from '../../../../../models/favorite';
|
import Favorite from '../../../../../models/favorite';
|
||||||
import Note from '../../../../../models/note';
|
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
import { getNote } from '../../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
stability: 'stable',
|
stability: 'stable',
|
||||||
|
@ -45,14 +45,11 @@ export const meta = {
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
export default define(meta, async (ps, user) => {
|
||||||
// Get favoritee
|
// Get favoritee
|
||||||
const note = await Note.findOne({
|
const note = await getNote(ps.noteId).catch(e => {
|
||||||
_id: ps.noteId
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (note === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchNote);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if already favorited
|
// if already favorited
|
||||||
const exist = await Favorite.findOne({
|
const exist = await Favorite.findOne({
|
||||||
noteId: note._id,
|
noteId: note._id,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import define from '../../../define';
|
||||||
import createNote from '../../../../../services/note/create';
|
import createNote from '../../../../../services/note/create';
|
||||||
import User from '../../../../../models/user';
|
import User from '../../../../../models/user';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
import { getNote } from '../../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -65,14 +66,11 @@ export const meta = {
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
export default define(meta, async (ps, user) => {
|
||||||
// Get votee
|
// Get votee
|
||||||
const note = await Note.findOne({
|
const note = await getNote(ps.noteId).catch(e => {
|
||||||
_id: ps.noteId
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (note === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchNote);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (note.poll == null) {
|
if (note.poll == null) {
|
||||||
throw new ApiError(meta.errors.noPoll);
|
throw new ApiError(meta.errors.noPoll);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue