mirror of
https://github.com/swissmakers/swiss-datashare.git
synced 2026-04-11 10:27:01 +02:00
* feat(localization): Added Thai translation * Formatted --------- Co-authored-by: Elias Schneider <login@eliasschneider.com>
39 lines
958 B
TypeScript
39 lines
958 B
TypeScript
import {
|
|
CanActivate,
|
|
ExecutionContext,
|
|
Injectable,
|
|
NotFoundException,
|
|
} from "@nestjs/common";
|
|
import { Request } from "express";
|
|
import * as moment from "moment";
|
|
import { PrismaService } from "src/prisma/prisma.service";
|
|
|
|
@Injectable()
|
|
export class ShareTokenSecurity implements CanActivate {
|
|
constructor(private prisma: PrismaService) {}
|
|
|
|
async canActivate(context: ExecutionContext) {
|
|
const request: Request = context.switchToHttp().getRequest();
|
|
const shareId = Object.prototype.hasOwnProperty.call(
|
|
request.params,
|
|
"shareId",
|
|
)
|
|
? request.params.shareId
|
|
: request.params.id;
|
|
|
|
const share = await this.prisma.share.findUnique({
|
|
where: { id: shareId },
|
|
include: { security: true },
|
|
});
|
|
|
|
if (
|
|
!share ||
|
|
(moment().isAfter(share.expiration) &&
|
|
!moment(share.expiration).isSame(0))
|
|
)
|
|
throw new NotFoundException("Share not found");
|
|
|
|
return true;
|
|
}
|
|
}
|