diff --git a/apps/expo/app/fissa/[pin]/index.tsx b/apps/expo/app/fissa/[pin]/index.tsx index f96c2cb..87cd81d 100644 --- a/apps/expo/app/fissa/[pin]/index.tsx +++ b/apps/expo/app/fissa/[pin]/index.tsx @@ -14,7 +14,7 @@ const Fissa = () => { if (!pin) return null; return ( - + { - const service = new FissaService(ctx, new SpotifyService()); - return service.detailsById(input); - }), pause: protectedProcedure.input(Z_PIN).mutation(({ ctx, input }) => { const service = new FissaService(ctx, new SpotifyService()); return service.pause(input, ctx.session.user.id); diff --git a/packages/api/src/service/FissaService.ts b/packages/api/src/service/FissaService.ts index 3a2d008..f075465 100644 --- a/packages/api/src/service/FissaService.ts +++ b/packages/api/src/service/FissaService.ts @@ -95,17 +95,6 @@ export class FissaService extends ServiceWithContext { return fissa; }; - detailsById = async (pin: string) => { - return this.db.fissa.findUnique({ - where: { pin }, - select: { - by: { select: { email: true } }, - expectedEndTime: true, - currentlyPlayingId: true, - }, - }); - }; - skipTrack = async (pin: string, userId: string) => { const fissa = await this.byId(pin, userId); @@ -155,9 +144,7 @@ export class FissaService extends ServiceWithContext { try { const isPlaying = await this.spotifyService.isStillPlaying(access_token); - if (!instantPlay && (!currentlyPlayingId || !isPlaying)) { - return this.stopFissa(pin, access_token); - } + if (!instantPlay && (!currentlyPlayingId || !isPlaying)) throw new Error("Stop fissa"); const nextTracks = this.getNextTracks(tracks, currentlyPlayingId); if (!nextTracks[0]) throw new NoNextTrack(); @@ -179,11 +166,15 @@ export class FissaService extends ServiceWithContext { }; private stopFissa = async (pin: string, accessToken: string) => { - await this.spotifyService.pause(accessToken); - return this.db.fissa.update({ - where: { pin }, - data: { currentlyPlaying: { disconnect: true } }, - }); + try { + await this.db.fissa.update({ + where: { pin }, + data: { currentlyPlaying: { disconnect: true } }, + }); + return this.spotifyService.pause(accessToken); + } catch (e) { + console.error(`${pin}, failed stopping fissa`, e); + } }; private getFissaDetailedInformation = async (pin: string) => { @@ -226,18 +217,15 @@ export class FissaService extends ServiceWithContext { { trackId, durationMs }: Pick, accessToken: string, ) => { - console.log({ accessToken }); - const promise = this.spotifyService.playTrack(accessToken, trackId); + await this.spotifyService.playTrack(accessToken, trackId); - await this.db.fissa.update({ + return this.db.fissa.update({ where: { pin }, data: { currentlyPlaying: { connect: { pin_trackId: { pin, trackId } } }, expectedEndTime: addMilliseconds(new Date(), durationMs), }, }); - - return promise; }; private getNextTracks = (tracks: Track[], currentlyPlayingId?: string | null) => {