All files / app/service jail.ts

27.77% Statements 10/36
0% Branches 0/1
0% Functions 0/6
27.77% Lines 10/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 6568x           68x   68x 68x   68x                     68x           68x             68x                       68x             68x                    
import { Empty } from "google-protobuf/google/protobuf/empty_pb";
import {
  AcceptCommunityGuidelinesReq,
  AcceptTOSReq,
  AcknowledgePendingModNoteReq,
  SetLocationReq,
} from "proto/jail_pb";
 
import client from "./client";
import { getCurrentUser } from "./user";
 
export async function getIsJailed() {
  const req = new Empty();
  const isJailed = (await client.jail.jailInfo(req)).getJailed();
  Iif (!isJailed) {
    const user = await getCurrentUser();
    return { isJailed, user };
  }
 
  return { isJailed, user: null };
}
 
export async function getJailInfo() {
  const req = new Empty();
  const res = await client.jail.jailInfo(req);
  return res.toObject();
}
 
export async function acceptTOS() {
  const req = new AcceptTOSReq();
  req.setAccept(true);
  const res = await client.jail.acceptTOS(req);
  return { isJailed: res.getJailed() };
}
 
export async function setLocation(
  city: string,
  lat: number,
  lng: number,
  radius: number
) {
  const req = new SetLocationReq();
  req.setCity(city).setLat(lat).setLng(lng).setRadius(radius);
  const res = await client.jail.setLocation(req);
  return { isJailed: res.getJailed() };
}
 
export async function setAcceptedCommunityGuidelines(accepted: boolean) {
  const req = new AcceptCommunityGuidelinesReq();
  req.setAccept(accepted);
  const res = await client.jail.acceptCommunityGuidelines(req);
  return { isJailed: res.getJailed() };
}
 
export async function acknowledgePendingModNote(
  modNoteId: number,
  acknowledge: boolean
) {
  const req = new AcknowledgePendingModNoteReq();
  req.setNoteId(modNoteId);
  req.setAcknowledge(acknowledge);
  const res = await client.jail.acknowledgePendingModNote(req);
  return { isJailed: res.getJailed() };
}