Refactor
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import Subscription from '../../../../models/sw-subscription';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import config from '../../../../config';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@@ -22,10 +21,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// if already subscribed
|
||||
const exist = await Subscription.findOne({
|
||||
userId: user._id,
|
||||
@@ -53,4 +49,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
|
||||
state: 'subscribed',
|
||||
key: config.sw.public_key
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
Reference in New Issue
Block a user