import { Service, SequelizeServiceOptions } from 'feathers-sequelize' // import { Params, Id, NullableId } from '@feathersjs/feathers' import { Application } from '../../declarations' // import { Forbidden } from '@feathersjs/errors' export class Party extends Service { app: Application constructor (options: Partial, app: Application) { super(options) this.app = app } // async find (params: Params): Promise<[]> { // const partyUsersModel = this.app.service('party-user').Model // const partys = await partyUsersModel.findAll({ // where: { // userId: params.user.userId // }, // attributes: [['partyId', 'id'], 'isMuted', 'isOwner'], // include: [ // { // model: this.getModel(params) // } // ] // }) // return partys // } // async get (id: Id, params: Params): Promise { // const partyUsersModel = this.app.service('party-user').Model // const party = await partyUsersModel.findOne({ // where: { // partyId: id, // userId: params.user.userId // }, // attributes: ['partyId', 'isMuted', 'isOwner'], // include: [{ model: this.getModel(params) }] // }) // if (!party) { // return await Promise.reject(new Forbidden('Party not found Or you don\'t have access!')) // } // return party // } // async create (data: any, params: Params): Promise { // const PartyUsersModel = this.app.service('party-user').Model // const PartyModel = this.getModel(params) // let savedGroup = new PartyModel(data) // savedGroup = await savedGroup.save() // // We are able to take benefit of using sequelize method *addUser* available due to *many to many* relationShip but // // that was making one extra Query for getting party details Therefore we are doing it manually // const userPartyModel = new PartyUsersModel({ // partyId: savedGroup.id, // userId: params.user.userId, // isOwner: true, // isInviteAccepted: true // }) // await userPartyModel.save() // // TODO: After saving party, update contacts via Socket // // TODO: If party is public update to all those users which are in same location // return savedGroup // } // async patch (id: NullableId, data: any, params?: Params): Promise { // // TODO: Handle socket update // return await super.patch(id, data, params) // } }