How to use the egg.Service function in egg

To help you get started, we’ve selected a few egg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DXY-F2E / api-mocker / server / app / service / cookie.js View on Github external
const Service = require('egg').Service

class Cookie extends Service {
  set (key, value, config = {}) {
    // cookie有效期,一个月
    const expires = new Date(Date.now() + 1000 * 60 * 60 * 24 * 30)
    this.ctx.cookies.set(key, value, Object.assign({
      expires,
      overwrite: true,
      secure: false,
      encrypt: true // 加密传输
    }, config))
  }
  get (key) {
    return this.ctx.cookies.get(key, {
      overwrite: true,
      encrypt: true
github 17disney / wait-times-service / app / service / park.js View on Github external
'use strict';

const Service = require('egg').Service;
const moment = require('moment');

class ParkService extends Service {
  async getByLocalDate(local, date, slice = 100000) {
    const find = {
      local,
      date,
    };

    const data = await this.ctx.model.DsPark.findOne(find, {
      _id: 0,
      markList: { $slice: -slice },
      flowList: { $slice: -slice },
      // markList: 0,
      // flowList: 0
    });
github unclexiao / egg-mp / app / service / sign.js View on Github external
'use strict';
const crypto = require('crypto');

const Service = require('egg').Service;

class SignService extends Service {
  // 生成随机字符串,用于微信支付
  createNonceStr() {
    return Math.random()
      .toString(36)
      .substr(2, 15);
  }

  // 生成时间戳,单位为秒,用于微信支付
  createTimestamp() {
    return parseInt(new Date().getTime() / 1000) + '';
  }

  // 序列化字符串
  raw(args) {
github MaleWeb / FullStack_Cli / app / service / admin / log.js View on Github external
const Service = require('egg').Service;

class Log extends Service {
    // 获取用户列表
    async getLogList(data) {
        let {ctx} = this;
        let uid = data.id ? data.id : '';
        let username = data.user_name ? data.user_name : '';
        let offset = (parseInt(data.pageIndex) - 1) * parseInt(data.pageSize);
        let limit = parseInt(data.pageSize);
        let state = parseInt(data.state);

        let total = await this.app.mysql.query('SELECT COUNT(*) total FROM fs_operation_logs WHERE operation_state=?',[state])
        let sql = ctx.helper.handleRequest({
            data:{
                id:uid,
                operation_state:state,
github wangweianger / zanePerfor / app / service / wx / analysis.js View on Github external
'use strict';

const Service = require('egg').Service;

class AnalysisService extends Service {

    // 用户漏斗分析列表
    async getAnalysislist(appId, beginTime, endTime, ip, pageNo, pageSize) {
        pageNo = pageNo * 1;
        pageSize = pageSize * 1;

        const query = { $match: { } };
        if (ip) query.$match.ip = ip;
        if (beginTime && endTime) query.$match.create_time = { $gte: new Date(beginTime), $lte: new Date(endTime) };

        return ip ? await this.oneThread(appId, query, pageNo, pageSize)
            : await this.moreThread(appId, beginTime, endTime, query, pageNo, pageSize);
    }
github hyperledger / cello / user-dashboard / src / app / service / chain.js View on Github external
/*
 SPDX-License-Identifier: Apache-2.0
*/
'use strict';

const Service = require('egg').Service;
const qs = require('qs');
const shell = require('shelljs');
const fs = require('fs-extra');
const rimraf = require('rimraf');
const moment = require('moment');

class ChainService extends Service {
  async list() {
    const { ctx, config } = this;
    const listUrl = config.operator.url.cluster.list;
    let chains = [];
    const response = await ctx.curl(`${listUrl}?${qs.stringify({
      user_id: ctx.user.id,
    })}`, {
      method: 'GET',
      timeout: 30000,
github xjh22222228 / tomato-work-server / app / service / mail.js View on Github external
'use strict';

const Service = require('egg').Service;
const qs = require('querystring');

class MailService extends Service {

  /**
   * 微信推送
   */
  wechatPush(data = {}) {
    const { ctx } = this;
    const params = qs.stringify({
      text: data.subject || '无标题',
      desp: data.text || data.html || '无内容'
    });
    
    ctx.curl(`https://sc.ftqq.com/${data.sckey}.send?${params}`);
  }
github hyperledger / cello / user-dashboard / src / app / service / deploy.js View on Github external
/*
 SPDX-License-Identifier: Apache-2.0
*/
'use strict';

const Service = require('egg').Service;

class DeployService extends Service {
  async list() {
    const { ctx } = this;
    const status = ctx.query.status || '';
    const total = await ctx.model.SmartContractDeploy.count({ user: ctx.user.id });
    const instantiatedCount = await ctx.model.SmartContractDeploy.count({ user: ctx.user.id, status: 'instantiated' });
    const instantiatingCount = await ctx.model.SmartContractDeploy.count({ user: ctx.user.id, status: 'instantiating' });
    const errorCount = await ctx.model.SmartContractDeploy.count({ user: ctx.user.id, status: 'error' });
    let data = [];
    if (status !== '') {
      data = await ctx.model.SmartContractDeploy.find({ user: ctx.user.id, status }, '_id name status deployTime').populate('smartContractCode chain smartContract', '_id version name chainId type size').sort('-deployTime');
    } else {
      data = await ctx.model.SmartContractDeploy.find({ user: ctx.user.id }, '_id name status deployTime').populate('smartContractCode chain smartContract', '_id version name chainId type size').sort('-deployTime');
    }
    return {
github DXY-F2E / api-mocker / server / app / service / user.js View on Github external
const Service = require('egg').Service
const md5 = require('blueimp-md5')

class UserService extends Service {
  async create (user) {
    return (await this.ctx.model.User({
      email: user.email,
      password: md5(user.password, this.config.md5Key),
      name: user.name
    }).save()).toObject()
  }
  getByEmail (email) {
    return this.ctx.model.User.findOne({
      email
    }).lean()
  }
  getById (id) {
github midwayjs / midway / benchmark / fixtures / egg-sample / app / service / user.js View on Github external
'use strict';

const Service = require('egg').Service;

class UserService extends Service {

  async getUser(options) {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          id: options.id,
          username: 'mockedName',
          phone: '12345678901',
          email: 'xxx.xxx@xxx.com',
        });
      }, 100);
    });
  }
}