Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
- import { Observable } from 'rxjs';
- import { GqlExecutionContext } from '@nestjs/graphql';
- import { default as slugify } from 'slugify';
- @Injectable()
- export class SlugInterceptor implements NestInterceptor {
- intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
- const ctx = GqlExecutionContext.create(context);
- const input = ctx.getArgs().input;
- if (input.title || input.slug) {
- if (!input.slug || input.slug === '') {
- input.slug = slugify(input.title, {
- lower: true,
- });
- } else {
- input.slug = slugify(input.slug, {
- replacement: '-',
- lower: true,
- });
- }
- }
- return next.handle();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement