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 | import { Injectable, NotFoundException } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; import { RemoteWorkRequest } from '../schemas'; import { RequestRemoteWorkDto, ActionRemoteWorkDto } from './dto/remote.dto'; @Injectable() export class RemoteWorkService { constructor( @InjectModel(RemoteWorkRequest.name) private requestModel: Model<RemoteWorkRequest>, ) {} async submitRequest( tenantId: string, employeeId: string, requestDto: RequestRemoteWorkDto, ) { const created = new this.requestModel({ ...requestDto, tenantId, employeeId, }); return created.save(); } async processAction( tenantId: string, requestId: string, actionDto: ActionRemoteWorkDto, approverId: string, ) { const request = await this.requestModel .findOne({ _id: requestId, tenantId }) .exec(); if (!request) throw new NotFoundException('Remote work request not found'); request.status = actionDto.action; request.approvedBy = approverId; await request.save(); // Side effect: If approved, we might need to flag the daily records or shift rules to skip Geofence/IP validation return request; } async getMyRequests(tenantId: string, employeeId: string) { return this.requestModel .find({ tenantId, employeeId }) .sort({ startDate: -1 }) .exec(); } } |