Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions configs/cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@
"responseTemplate": "<%= `deleted: ${deleted.length}` %>"
}
},
{
"rule": "0 1 * * *",
"method": "notification.fcm-token.remove",
"description": "Cleanup 2 months old fcm tokens",
"payload": {
"params": {
"query": {
"where": {
"updatedAt": {
"<": "<%= new Date().setMonth(new Date().getMonth() - 2) %>"
}
}
},
"payload": {
"authorization": {
"filter": {
"methodOptions": {
"isAllowMultiple": true
}
}
}
}
},
"allowErrorCodes": [-33485],
"responseTemplate": "<%= `deleted: ${deleted.length}` %>"
}
},
{
"rule": "* * * * *",
"method": "notification.job.task.process",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,22 +325,22 @@
{
"microservice": "notification",
"method": "fcm-token.remove",
"description": "Remove FCM token",
"description": "Remove FcmToken by given condition",
"allowGroup": [
"admin"
],
"denyGroup": [],
"createdAt": "2025-03-10T18:03:29.296Z",
"modelIn": "notification.FcmTokenRemoveInput",
"modelOut": "notification.FcmTokenRemoveOutput",
"createdAt": "2025-03-17T09:02:17.638Z",
"modelIn": "RemoveRequestParams",
"modelOut": "notification.RemoveOutputParams.7e57e480187ae365dff017e73a6af35c",
"methodFilters": []
},
{
"microservice": "notification",
"method": "fcm-token.save",
"description": "Save FCM token for user",
"allowGroup": [
"admin"
"user"
],
"denyGroup": [],
"createdAt": "2025-03-10T18:03:29.296Z",
Expand All @@ -350,15 +350,41 @@
},
{
"microservice": "notification",
"method": "fcm-token.remove-user-tokens",
"description": "Remove all FCM tokens for a user",
"method": "fcm-token.list",
"description": "Returns list of FcmToken by given condition",
"allowGroup": [
"admin"
],
"denyGroup": [],
"createdAt": "2025-03-17T09:02:17.638Z",
"modelIn": "ListRequestParams",
"modelOut": "notification.ListOutputParams.07cb21604c24f47f2672215971731023",
"methodFilters": []
},
{
"microservice": "notification",
"method": "fcm-token.view",
"description": "Returns FcmToken by given condition",
"allowGroup": [
"admin"
],
"denyGroup": [],
"createdAt": "2025-03-17T09:02:17.638Z",
"modelIn": "ViewRequestParams",
"modelOut": "notification.ViewOutputParams.c7183e89e574222a2a3d0fca89605104",
"methodFilters": []
},
{
"microservice": "notification",
"method": "fcm-token.count",
"description": "Returns count of FcmToken by given condition",
"allowGroup": [
"admin"
],
"denyGroup": [],
"createdAt": "2025-03-10T19:45:43.110Z",
"modelIn": "notification.FcmTokenRemoveUserTokensInput",
"modelOut": "notification.FcmTokenRemoveUserTokensOutput",
"createdAt": "2025-03-17T09:02:17.638Z",
"modelIn": "CountRequestParams",
"modelOut": "CountOutputParams",
"methodFilters": []
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"task": "notification.Task",
"recipient": "notification.Recipient"
},
"createdAt": "2022-04-14T05:34:31.136Z"
"createdAt": "2025-03-17T09:02:17.638Z"
},
{
"microservice": "notification",
Expand All @@ -128,7 +128,7 @@
}
}
},
"createdAt": "2022-04-14T05:34:31.136Z"
"createdAt": "2025-03-17T09:02:17.638Z"
},
{
"microservice": "notification",
Expand Down Expand Up @@ -807,8 +807,8 @@
},
{
"microservice": "notification",
"alias": "notification.FcmTokenRemoveInput",
"title": "Fcm Token Remove Input",
"alias": "notification.FcmToken",
"title": "Fcm Token",
"schema": {
"token": {
"in": {
Expand All @@ -817,32 +817,34 @@
"out": {
"admin": "allow"
}
}
},
"createdAt": "2025-03-10T18:03:29.296Z"
},
{
"microservice": "notification",
"alias": "notification.FcmTokenRemoveOutput",
"title": "Fcm Token Remove Output",
"schema": {
"success": {
},
"userId": {
"in": {
"user": {
"condition": "Fields: user owner"
}
},
"out": {
"admin": "allow"
}
},
"userAgent": {
"in": {
"admin": "allow"
},
"out": {
"admin": "allow"
}
}
},
"createdAt": "2025-03-10T18:03:29.296Z"
},
{
"microservice": "notification",
"alias": "notification.FcmTokenRemoveUserTokensInput",
"title": "Fcm Token Remove User Tokens Input",
"schema": {
"userId": {
},
"createdAt": {
"in": {
"admin": "allow"
},
"out": {
"admin": "allow"
}
},
"updatedAt": {
"in": {
"admin": "allow"
},
Expand All @@ -851,14 +853,15 @@
}
}
},
"createdAt": "2025-03-10T19:45:43.110Z"
"createdAt": "2025-03-17T09:02:17.638Z"
},
{
"microservice": "notification",
"alias": "notification.FcmTokenRemoveUserTokensOutput",
"title": "Fcm Token Remove User Tokens Output",
"alias": "notification.ListOutputParams.07cb21604c24f47f2672215971731023",
"title": "List Output Params",
"schema": {
"success": {
"list": "notification.FcmToken",
"count": {
"in": {
"admin": "allow"
},
Expand All @@ -867,6 +870,25 @@
}
}
},
"createdAt": "2025-03-10T19:45:43.110Z"
"createdAt": "2025-03-17T09:02:17.638Z"
},
{
"microservice": "notification",
"alias": "notification.ViewOutputParams.c7183e89e574222a2a3d0fca89605104",
"title": "View Output Params",
"schema": {
"entity": "notification.FcmToken"
},
"createdAt": "2025-03-17T09:02:17.638Z"
},
{
"microservice": "notification",
"alias": "notification.RemoveOutputParams.7e57e480187ae365dff017e73a6af35c",
"title": "Remove Output Params",
"schema": {
"deleted": "notification.FcmToken",
"entities": "notification.FcmToken"
},
"createdAt": "2025-03-17T09:02:17.638Z"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export default class useUseridAndUseragentAsPk1742223121658 implements MigrationInterface {
name = 'useUseridAndUseragentAsPk1742223121658';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "public"."IDX_fcm_token_userId"`);
await queryRunner.query(`DROP INDEX "public"."IDX_fcm_token_token"`);
await queryRunner.query(`ALTER TABLE "fcm_token" DROP CONSTRAINT IF EXISTS "PK_fcm_token"`);
await queryRunner.query(`UPDATE "fcm_token"
SET "userAgent" = ''
WHERE "userAgent" IS NULL`);
await queryRunner.query(`ALTER TABLE "fcm_token"
ALTER COLUMN "userAgent" SET NOT NULL`);
await queryRunner.query(`ALTER TABLE "fcm_token"
ADD CONSTRAINT "PK_fcm_token_new" PRIMARY KEY ("userId", "userAgent")`);
await queryRunner.query(`ALTER TABLE "fcm_token"
ADD CONSTRAINT "UQ_fcm_token_token" UNIQUE ("token")`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "fcm_token" DROP CONSTRAINT "UQ_fcm_token_token"`);
await queryRunner.query(`ALTER TABLE "fcm_token" DROP CONSTRAINT "PK_fcm_token_new"`);
await queryRunner.query(`ALTER TABLE "fcm_token"
ALTER COLUMN "userAgent" DROP NOT NULL`);
await queryRunner.query(`ALTER TABLE "fcm_token"
ADD CONSTRAINT "PK_fcm_token" PRIMARY KEY ("token")`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_fcm_token_token" ON "fcm_token" ("token") `);
await queryRunner.query(`CREATE INDEX "IDX_fcm_token_userId" ON "fcm_token" ("userId") `);
}
}
16 changes: 8 additions & 8 deletions microservices/notification/src/entities/fcm-token.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { IsTypeormDate, IsUndefinable } from '@lomray/microservice-helpers';
import { IsTypeormDate } from '@lomray/microservice-helpers';
import { IsString, Length } from 'class-validator';
import { JSONSchema } from 'class-validator-jsonschema';
import { Entity, Column, CreateDateColumn, Index, UpdateDateColumn, PrimaryColumn } from 'typeorm';
import { Entity, Column, CreateDateColumn, UpdateDateColumn, PrimaryColumn, Unique } from 'typeorm';

@JSONSchema({
title: 'FCM Token',
})
@Entity()
class FcmToken {
@PrimaryColumn({ type: 'varchar', length: 255 })
@Column({ type: 'varchar', length: 255 })
@Length(1, 255)
@IsString()
@Unique(['token'])
token: string;

@Index('IDX_fcm_token_userId', ['userId'])
@Column({ type: 'varchar', length: 36 })
@PrimaryColumn({ type: 'varchar', length: 36 })
@Length(1, 36)
@IsString()
userId: string;

@Column({ type: 'varchar', length: 255, nullable: true })
@Column({ type: 'varchar', length: 255 })
@Length(1, 255)
@IsString()
@IsUndefinable()
userAgent?: string;
@PrimaryColumn()
userAgent: string;

@IsTypeormDate()
@CreateDateColumn()
Expand Down
13 changes: 13 additions & 0 deletions microservices/notification/src/methods/fcm-token/crud.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Endpoint } from '@lomray/microservice-helpers';
import { getRepository } from 'typeorm';
import FcmToken from '@entities/fcm-token';

/**
* CRUD controller for FCMToken entities
*/
const crud = Endpoint.controller(() => getRepository(FcmToken), {
restore: false,
create: false,
});

export default crud;

This file was deleted.

Loading
Loading