-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into docs/block-diagram
- Loading branch information
Showing
17 changed files
with
1,014 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,5 @@ lerna-debug.log* | |
!.vscode/extensions.json | ||
|
||
# Environment variable file | ||
.env | ||
.env | ||
.schema.gpl |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
apps/api/src/modules/notifications/dtos/create-notification-attachment.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
IsNotEmpty, | ||
ValidateIf, | ||
registerDecorator, | ||
ValidationOptions, | ||
ValidationArguments, | ||
} from 'class-validator'; | ||
import { Stream } from 'stream'; | ||
|
||
export class CreateNotificationAttachmentDto { | ||
@IsNotEmpty({ message: 'Filename cannot be empty' }) | ||
filename: string; | ||
|
||
@IsNotEmpty({ message: 'Content or path must be provided' }) | ||
@ValidateIf((obj) => !obj.path, { message: 'Content or path must be provided' }) | ||
content: string | Buffer | Stream; | ||
|
||
@IsNotEmpty({ message: 'Content or path must be provided' }) | ||
@ValidateIf((obj) => !obj.content, { message: 'Content or path must be provided' }) | ||
path: string; | ||
} | ||
|
||
// TODO: Custom Validator added for the bug | ||
// https://github.com/OsmosysSoftware/osmo-notify/pull/62 | ||
export function AttachmentValidation(validationOptions?: ValidationOptions) { | ||
return function (object: unknown, propertyName: string) { | ||
registerDecorator({ | ||
name: 'attachmentValidation', | ||
target: object.constructor, | ||
propertyName: propertyName, | ||
options: validationOptions, | ||
validator: { | ||
validate(value: unknown[]) { | ||
if (!value || value.length === 0) { | ||
return false; | ||
} | ||
|
||
for (const attachment of value) { | ||
const path = attachment['path']; | ||
const content = attachment['content']; | ||
const filename = attachment['filename']; | ||
|
||
if ((!path && !content) || !filename?.length) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
}, | ||
defaultMessage(args: ValidationArguments) { | ||
if (!args.value || args.value.length === 0) { | ||
return 'Attachments must be provided'; | ||
} | ||
|
||
for (const attachment of args.value) { | ||
if (!attachment['filename']?.length) { | ||
return 'Filename cannot be empty'; | ||
} | ||
|
||
if (!attachment['content'] && !attachment['path']) { | ||
return 'Content or path must be provided for each attachment'; | ||
} | ||
} | ||
|
||
return 'Invalid attachments'; | ||
}, | ||
}, | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
apps/api/src/modules/notifications/notifications.resolver.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { NotificationsResolver } from './notifications.resolver'; | ||
|
||
describe('NotificationsResolver', () => { | ||
let resolver: NotificationsResolver; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [NotificationsResolver], | ||
}).compile(); | ||
|
||
resolver = module.get<NotificationsResolver>(NotificationsResolver); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(resolver).toBeDefined(); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
apps/api/src/modules/notifications/notifications.resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Query, Resolver } from '@nestjs/graphql'; | ||
import { NotificationsService } from './notifications.service'; | ||
import { Notification } from './entities/notification.entity'; | ||
import { ApiKeyGuard } from 'src/common/guards/api-key/api-key.guard'; | ||
import { UseGuards } from '@nestjs/common'; | ||
|
||
@Resolver(() => Notification) | ||
@UseGuards(ApiKeyGuard) | ||
export class NotificationsResolver { | ||
constructor(private readonly notificationsService: NotificationsService) {} | ||
|
||
@Query(() => [Notification], { name: 'notifications' }) | ||
async findAll(): Promise<Notification[]> { | ||
return this.notificationsService.getAllNotifications(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.