private ArrayList<Lesson> lessons = new ArrayList<Lesson>();
@Override
public int addLesson(Lesson lesson) {
lessons.add(lesson);
return lessons.size();
}
const { id: artistId } = req.params;
const albums = await Album.find({artist: artist._id});
if (!albums?.length) {
return res.status(404).send({error: 'Album or artist not found!'});
}
const albumsIds = albums.map(album => album._id);
const allTracks = await Track.find({ album: { $in: albumsIds } });
if (!allTracks?.length) {
return res.status(404).send({error: 'Tracks not found!'});
}
const tracksIds = allTracks .map(track=> track._id);
await TrackHistory.deleteMany({ track: { $in: tracksIds } });
await Track.deleteMany({ album: { $in: albumsIds } });
await Album.deleteMany({artist: artistId});
await Artist.deleteOne({ _id: artistId});
res.send('Delete successful!');
var object = {
method: {
method: () => console.log('123123')
}
}
let string = 'object.method.method'
const method = _.get(window, string);
function fn() {
const object = {
method: {
method: () => console.log('123123')
}
}
this.object = object;
let string = 'object.method.method'
const method = _.get(this, string);
}
function getNestedValue(object, path) {
path = path.replace(/\[(\w+)\]/g, '.$1'); // конвертация индексов в свойства
path = path.replace(/^\./, ''); // удаление лишних точек
const parts = path.split('.');
for (const key of parts) {
if (typeof object === 'object' && !(key in object)) return;
object = object[key];
}
return object;
}
console.log(getNestedValue(window, 'object.method.method'));
@Entity()
export class User {
@PrimaryGeneratedColumn()
public id: number;
// ...
@OneToMany(() => BankProp, (prop) => prop.user)
public bankProps: Array<BankProp>;
}
@Entity()
export class BankProp {
@PrimaryGeneratedColumn()
public id: number;
@Column()
public userId: number;
@ManyToOne(() => User, (user) => user.bankProps)
public user: User;
// ...
}
///
const result = await userRepository.find({
relations: {
bankProps: true
}
});
import { Inject } from '@nestjs/common';
import { REQUEST } from '@nestjs/core';
@Injectable()
export class SessionService {
constructor(@Inject(REQUEST) private readonly req: Express.Request) {};
write(userId: number) {
this.req.session.userId = userId;
}
read() {
return this.req.session.userId;
}
}
const validConditions = {
$and: [
{
$or: [
{ 'conditions.age': { $exists: false } },
{ 'conditions.age': 20 },
],
},
{
$or: [
{ 'conditions.name': { $exists: false } },
{ 'conditions.name': 'John' },
],
},
{
$or: [
{ 'conditions.surname': { $exists: false } },
{ 'conditions.surname': 'White' },
],
},
],
};
const result = await Test.find(validConditions);
SELECT * FROM entries WHERE age = 20 OR age IS NULL AND name = 'John' OR name IS NULL AND surname = 'White' OR surname IS NULL
int text;
// если результат функции false, т.е. конвертирование прошло неудачно, показываем табличку с ошибкой
if(!int.TryParse(textBox1.Text, out text)) MessageBox.Show("Input value is invalid");
static class Extensions
{
public static IEnumerable<TSource> Remove<TSource>(this IEnumerable<TSource> collection, Predicate<TSource> predicate)
{
foreach(TSource item in collection)
{
if(!predicate?.Invoke(item)) yield return item;
}
}
}
class Program
{
public static void Main()
{
IEnumerable<Shape> shapes = new List<Shape> { new Square(), new Triangle(), new Circle(), new Circle() };
foreach(var shape in shapes.Remove(t => t.GetType() == typeof(Circle)))
{
Console.WriteLine(shape.GetType()); // Square, Triangle
}
}
}
public void DeleteCar(string carModel, string color, double speed, int yearOfIssue)
{
Car car = cars.FirstOrDefault(c => c.CarModel == carModel && c.Color == color && c.Speed == speed && c.YearOfIssue == yearOfIssue);
cars.Remove(car);
}
using System;
using System.Runtime.InteropServices;
class Example
{
// Use DllImport to import the Win32 MessageBox function.
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);
static void Main()
{
// Call the MessageBox function using platform invoke.
MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
}
}