Skip to content

Commit 8f102e0

Browse files
Update SFTP filename (#267)
Updates the filename for Observations sent to SFTP server. Also refactors the database connections. --------- Co-authored-by: danielbenner <[email protected]>
1 parent ce8a5cd commit 8f102e0

File tree

5 files changed

+285
-180
lines changed

5 files changed

+285
-180
lines changed

plugins/sftp/service/src/adapters/adapters.sftp.mongoose.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const SftpObservationsSchema = new mongoose.Schema({
1212
eventId: { type: Number, required: true, unique: true },
1313
observationId: { type: String, required: true },
1414
status: { type: String, enum: Object.values(SftpStatus), required: true }
15-
},{
16-
timestamps: { createdAt: 'createdAt',updatedAt: 'updatedAt' }
15+
}, {
16+
timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' }
1717
});
1818

1919
export interface SftpAttrs {
@@ -48,17 +48,17 @@ export class MongooseSftpObservationRepository implements SftpObservationReposit
4848
}
4949

5050
async findAll(eventId: MageEventId): Promise<SftpAttrs[]> {
51-
const documents = await this.model.find({eventId: eventId})
51+
const documents = await this.model.find({ eventId: eventId })
5252
return documents.map(document => document.toJSON())
5353
}
5454

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

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import mongoose from 'mongoose';
2+
3+
const TeamSchema = new mongoose.Schema({
4+
name: { type: String, required: true },
5+
userIds: [{ type: mongoose.Schema.Types.ObjectId }],
6+
id: { type: String, required: true },
7+
acl: { type: Object, required: true }
8+
});
9+
10+
export interface TeamDoc extends mongoose.Document {
11+
name: string;
12+
id: mongoose.Types.ObjectId;
13+
userIds: mongoose.Types.ObjectId[];
14+
teamEventId?: string;
15+
}
16+
17+
export class MongooseTeamsRepository {
18+
readonly model: mongoose.Model<TeamDoc>;
19+
20+
constructor(connection: mongoose.Connection) {
21+
this.model = connection.model<TeamDoc>('teams', TeamSchema);
22+
}
23+
24+
async findTeamsByUserId(userId: string | undefined): Promise<TeamDoc[]> {
25+
if (!userId) {
26+
return [];
27+
}
28+
const userObjectId = new mongoose.Types.ObjectId(userId);
29+
const teams = await this.model.find({ userIds: userObjectId }).exec();
30+
return teams.map(team => team.toJSON() as TeamDoc);
31+
}
32+
}

0 commit comments

Comments
 (0)