Skip to content

Commit

Permalink
add notification on queue move and update ci files
Browse files Browse the repository at this point in the history
  • Loading branch information
hofstede-matheus committed Oct 2, 2023
1 parent 3908d23 commit 19d594e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/google-cloudrun-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

# - name: Google Auth
# id: auth
# uses: 'google-github-actions/auth@v0'
# with:
# token_format: 'access_token'
# workload_identity_provider: '${{ secrets.WIF_PROVIDER }}' # e.g. - projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider
# service_account: '${{ secrets.WIF_SERVICE_ACCOUNT }}' # e.g. - [email protected]

# NOTE: Alternative option - authentication via credentials json
- name: Google Auth
id: auth
uses: 'google-github-actions/auth@v0'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
token_format: 'access_token'
workload_identity_provider: '${{ secrets.WIF_PROVIDER }}' # e.g. - projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider
service_account: '${{ secrets.WIF_SERVICE_ACCOUNT }}' # e.g. - [email protected]

# NOTE: Alternative option - authentication via credentials json
# - name: Google Auth
# id: auth
# uses: 'google-github-actions/auth@v0'
# with:
# credentials_json: '${{ secrets.GCP_CREDENTIALS }}'

# BEGIN - Docker auth and build (NOTE: If you already have a container image, these Docker steps can be omitted)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ export class TypeOrmClientsRepository implements ClientRepository {
private readonly clientsRepository: Repository<Client>,
) {}

getTokenFromClient(clientId: string): Promise<string> {
const token = this.clientsRepository.query(
`
select fcm_token from fcm_tokens where client_id = $1
`,
[clientId],
);

return token;
}

async addTokenToClient(clientId: string, token: string): Promise<void> {
const clientToken = await this.clientsRepository.query(
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface ClientRepository {
}): Promise<void>;

addTokenToClient(clientId: string, token: string): Promise<void>;
getTokenFromClient(clientId: string): Promise<string | undefined>;
}

export const ClientRepository = Symbol('ClientRepository');
2 changes: 2 additions & 0 deletions src/modules/desk/desk.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import { UpdateDeskUsecase } from './interactors/usecases/UpdateDeskUsecase';
import { CallNextClientOfDeskUsecase } from './interactors/usecases/CallNextClientOfDeskUsecase';
import { ServicesModule } from '../services/services.module';
import { QueuesModule } from '../queues/queues.module';
import { ClientsModule } from '../clients/clients.module';

@Module({
imports: [
CommonModule,
forwardRef(() => ServicesModule),
forwardRef(() => QueuesModule),
forwardRef(() => ClientsModule),
TypeOrmModule.forFeature([Desk]),
],
controllers: [DeskController],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { QueueRepository } from '../../../queues/domain/repositories/QueueReposi
import { QueueEntity } from '../../../queues/domain/entities/Queue.entity';
import { DeskWithCalledClient } from '../../domain/entities/Desk.entity';
import { DeskRepository } from '../../domain/repositories/DeskRepository';
import {
NotificationService,
NotificationTypes,
} from '../../../common/domain/services/NotificationService';
import { ClientRepository } from '../../../clients/domain/repositories/ClientRepository';

@Injectable()
export class CallNextClientOfDeskUsecase implements UseCase {
Expand All @@ -21,6 +26,12 @@ export class CallNextClientOfDeskUsecase implements UseCase {

@Inject(QueueRepository)
private queueRepository: QueueRepository,

@Inject(NotificationService)
private notificationService: NotificationService,

@Inject(ClientRepository)
private clientRepository: ClientRepository,
) {}
async execute(
deskId: string,
Expand Down Expand Up @@ -54,6 +65,26 @@ export class CallNextClientOfDeskUsecase implements UseCase {
);

// TODO: notify queue subscriber
this.notificationService.sendNotification(
client.queueId,
'A fila andou',
'A fila andou',
NotificationTypes.TO_TOPIC,
);

// TODO: notify client when he is called
const tokenFromClient = await this.clientRepository.getTokenFromClient(
client.id,
);

if (tokenFromClient) {
this.notificationService.sendNotification(
tokenFromClient,
'Você foi chamado',
'Você foi chamado',
NotificationTypes.TO_TOKEN,
);
}

const desk = await this.deskRepository.findById(deskId);

Expand Down

0 comments on commit 19d594e

Please sign in to comment.