<commit_before>import Order from '../models/order.model';
import authCtrl from './auth.controller';

function create(fromUser, toUser, weekday, timeQuantum) {
    return new Promise(function (resolve, reject) {
        const order = new Order();
        order.fromUser = fromUser;
        order.toUser = toUser;
        order.weekday = weekday;
        order.timeQuantum = timeQuantum;

        order.save()
            .then(newOrder => {
                resolve(newOrder);
            })
            .catch(e => {
                reject(e)
            })
    })
}

function newOrder(req, res, next) {
    let { token, target, weekday, time } = req.query;
    authCtrl.checkToken(token)
        .then(user => {
            Order.findOrderByFrom(user._id, target, weekday, time)
                .then(order => {
                    if (order.orderStatus === 0 || order.orderStatus === 3) {
                        res.json({
                            status: 'err',
                            msg: '您已经发过申请了，请不要重复发送'
                        })
                    } else {
                        create(user._id, target, weekday, time)
                            .then(newOrde => {
                                res.json({
                                    status: 'ok',
                                    newOrder
                                })
                            })
                            .catch(e => {
                                res.json({
                                    status: 'err',
                                    msg: e
                                })
                            })
                    }
                })
                .catch(e => {
                    create(user._id, target, weekday, time)
                        .then(newOrder => {
                            res.json({
                                status: 'ok',
                                newOrder
                            })
                        })
                        .catch(e => {
                            res.json({
                                status: 'err',
                                msg: e
                            })
                        })
                })
        })
        .catch(e => {
            res.json({
                status: 'err',
                msg: e
            })
        })
}


export default { createOrder };<commit_msg>chang function name<commit_after>import Order from '../models/order.model';
import authCtrl from './auth.controller';

function create(fromUser, toUser, weekday, timeQuantum) {
    return new Promise(function (resolve, reject) {
        const order = new Order();
        order.fromUser = fromUser;
        order.toUser = toUser;
        order.weekday = weekday;
        order.timeQuantum = timeQuantum;

        order.save()
            .then(newOrder => {
                resolve(newOrder);
            })
            .catch(e => {
                reject(e)
            })
    })
}

function newOrder(req, res, next) {
    let { token, target, weekday, time } = req.query;
    authCtrl.checkToken(token)
        .then(user => {
            Order.findOrderByFrom(user._id, target, weekday, time)
                .then(order => {
                    if (order.orderStatus === 0 || order.orderStatus === 3) {
                        res.json({
                            status: 'err',
                            msg: '您已经发过申请了，请不要重复发送'
                        })
                    } else {
                        create(user._id, target, weekday, time)
                            .then(newOrde => {
                                res.json({
                                    status: 'ok',
                                    newOrder
                                })
                            })
                            .catch(e => {
                                res.json({
                                    status: 'err',
                                    msg: e
                                })
                            })
                    }
                })
                .catch(e => {
                    create(user._id, target, weekday, time)
                        .then(newOrder => {
                            res.json({
                                status: 'ok',
                                newOrder
                            })
                        })
                        .catch(e => {
                            res.json({
                                status: 'err',
                                msg: e
                            })
                        })
                })
        })
        .catch(e => {
            res.json({
                status: 'err',
                msg: e
            })
        })
}


export default { newOrder };
{'fraction_non_alphanumeric': 0.09960735689191982, 'fraction_numerical': 0.0008266170696424882, 'mean_word_length': 0.6799722318639362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4137612', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1083, 'n_words': 208}