Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
10 changes: 5 additions & 5 deletions plugins/sftp/service/src/adapters/adapters.sftp.mongoose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const SftpObservationsSchema = new mongoose.Schema({
eventId: { type: Number, required: true, unique: true },
observationId: { type: String, required: true },
status: { type: String, enum: Object.values(SftpStatus), required: true }
},{
timestamps: { createdAt: 'createdAt',updatedAt: 'updatedAt' }
}, {
timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' }
});

export interface SftpAttrs {
Expand Down Expand Up @@ -48,17 +48,17 @@ export class MongooseSftpObservationRepository implements SftpObservationReposit
}

async findAll(eventId: MageEventId): Promise<SftpAttrs[]> {
const documents = await this.model.find({eventId: eventId})
const documents = await this.model.find({ eventId: eventId })
return documents.map(document => document.toJSON())
}

async findAllByStatus(eventId: MageEventId, status: SftpStatus[]): Promise<SftpAttrs[]> {
const documents = await this.model.find({eventId: eventId, status: { $in: status}})
const documents = await this.model.find({ eventId: eventId, status: { $in: status } })
return documents.map(document => document.toJSON())
}

async findLatest(eventId: MageEventId): Promise<SftpAttrs | null> {
const document = await this.model.findOne({ eventId: eventId }, { updatedAt: true }, { sort: { updatedAt: -1 }, limit: 1 })
const document = await this.model.findOne({ eventId: eventId }, { updatedAt: true }, { sort: { updatedAt: -1 }, limit: 1 })
return document ? (document.toJSON() as SftpAttrs) : null
}

Expand Down
32 changes: 32 additions & 0 deletions plugins/sftp/service/src/adapters/adapters.sftp.teams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import mongoose from 'mongoose';

const TeamSchema = new mongoose.Schema({
name: { type: String, required: true },
userIds: [{ type: mongoose.Schema.Types.ObjectId }],
id: { type: String, required: true },
acl: { type: Object, required: true }
});

export interface TeamDoc extends mongoose.Document {
name: string;
id: mongoose.Types.ObjectId;
userIds: mongoose.Types.ObjectId[];
teamEventId?: string;
}

export class MongooseTeamsRepository {
readonly model: mongoose.Model<TeamDoc>;

constructor(connection: mongoose.Connection) {
this.model = connection.model<TeamDoc>('teams', TeamSchema);
}

async findTeamsByUserId(userId: string | undefined): Promise<TeamDoc[]> {
if (!userId) {
return [];
}
const userObjectId = new mongoose.Types.ObjectId(userId);
const teams = await this.model.find({ userIds: userObjectId }).exec();
return teams.map(team => team.toJSON() as TeamDoc);
}
}
Loading